* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f7f4ef;
  color: #1a1a1a;
}

header {
  padding: 1rem 1.5rem;
  background: #2d4a3e;
  color: #f5f5f0;
}

.lang-select {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.lang-select-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: #c8d9d0;
}

.lang-select-control {
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #5a7a6a;
  background: #f5f5f0;
  color: #1a1a1a;
}

header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
}

.subtitle {
  margin: 0.25rem 0 0.75rem;
  font-size: 0.95rem;
  color: #c8d9d0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.puzzle-select {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: #c8d9d0;
}

.puzzle-select-control {
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #5a7a6a;
  background: #f5f5f0;
  color: #1a1a1a;
}

.load-row {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.load-row button {
  padding: 0.45rem 0.9rem;
  font-size: 0.95rem;
  border: none;
  border-radius: 4px;
  background: #e8f0ec;
  color: #1a1a1a;
  cursor: pointer;
}

.load-row button:hover {
  background: #fff;
}

.editor-link {
  color: #c8d9d0;
  font-size: 0.9rem;
}

.load-message {
  margin: 0.75rem 0 0;
  color: #ffd89b;
  font-size: 0.9rem;
}

main {
  padding: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

.game-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.board-section {
  flex: 0 0 auto;
}

.current-word {
  min-height: 2rem;
  margin-bottom: 0.75rem;
  font-family: ui-monospace, monospace;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #2d4a3e;
}

.board-wrapper {
  position: relative;
  display: inline-block;
  padding-top: 2rem;
  padding-left: 0.25rem;
}

.rotate-btn {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #555;
  cursor: pointer;
  transition: color 0.2s, background 0.15s;
}

.rotate-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.rotate-btn.rotated {
  color: #22c55e;
}

.rotate-btn:focus-visible {
  outline: 2px solid #4a7c59;
  outline-offset: 2px;
}

.board-rotator-slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1),
    height 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.board-rotator {
  position: relative;
  display: inline-block;
  transform-origin: center center;
}

.path-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.board {
  display: inline-grid;
  gap: 4px;
  padding: 8px;
  background: #e0dbd3;
  border-radius: 8px;
}

.board-tiles {
  position: relative;
  z-index: 1;
  outline: none;
}

.board-tiles:focus-visible {
  box-shadow: 0 0 0 3px #4a7c59;
}

.board-letters {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  gap: 4px;
  padding: 8px;
  pointer-events: none;
}

.letter-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, monospace;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #1a1a1a;
  transform-origin: center center;
  pointer-events: none;
}

.letter-cell.finished-letter {
  opacity: 0.45;
}

.tile {
  position: relative;
  width: 4.5rem;
  height: 4.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, monospace;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  background: #fff;
  border-radius: 6px;
  user-select: none;
  touch-action: none;
  cursor: pointer;
  transition: background 0.1s, opacity 0.15s;
  transform-origin: center center;
}

.tile.blank {
  background: #d8d3cb;
  cursor: default;
}

.tile.in-path {
  background: #b8d4be;
  box-shadow: inset 0 0 0 2px #4a7c59;
}

.tile.finished {
  opacity: 0.45;
  background: #e8e4dc;
}

.tile.shake {
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.hint {
  position: absolute;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.hint-start {
  left: 4px;
  bottom: 3px;
  color: #2ecc71;
}

.hint-contains {
  right: 4px;
  bottom: 3px;
  color: #1a1a1a;
}

.path-lines line {
  stroke: #e8833a;
  stroke-width: 4;
  stroke-linecap: round;
}

.feedback {
  min-height: 1.5rem;
  margin: 0.75rem 0 0;
  font-size: 0.95rem;
  color: #555;
}

.feedback.error {
  color: #a33;
}

.word-panel {
  flex: 1;
  min-width: 16rem;
}

.hint-debug {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: #666;
}

.hint-debug select {
  font-size: 0.9rem;
  padding: 0.3rem 0.4rem;
  max-width: 12rem;
}

.level3-hints {
  margin-bottom: 1rem;
  padding: 0.6rem 0.75rem;
  background: #eef5f0;
  border-radius: 4px;
  border: 1px solid #c5d9cc;
}

.level3-option {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  cursor: pointer;
}

.level3-option:last-child {
  margin-bottom: 0;
}

.progress-header {
  margin-bottom: 1.25rem;
}

.progress-summary {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #2d4a3e;
}

.progress-summary.finished {
  color: #1b6b3a;
}

.restart-btn {
  margin-top: 0.6rem;
  padding: 0.4rem 0.85rem;
  font-size: 0.9rem;
  border: 1px solid #888;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.restart-btn:hover {
  background: #f0f0f0;
}

.length-group {
  margin-bottom: 1.25rem;
}

.length-group h3 {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
}

.length-group .found-words {
  font-family: ui-monospace, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  word-spacing: 0.2em;
}

.length-group .word-hint {
  color: #888;
}

.length-group .remaining {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: #777;
}

.bonus-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 2px solid #d0cbc3;
}

.bonus-section h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
}

.bonus-list {
  font-family: ui-monospace, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  word-spacing: 0.2em;
}

@media (max-width: 700px) {
  .tile {
    width: 3.5rem;
    height: 3.5rem;
    font-size: 1.6rem;
  }

  .letter-cell {
    font-size: 1.6rem;
  }
}
