/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:           #f0e6d3;
  --surface:      #f7f0e4;
  --surface-2:    #ebe0c8;
  --accent:       #c4603a;
  --accent-2:     #d4854a;
  --tile-bg:      #eedfa8;
  --tile-border:  #c49848;
  --tile-shadow:  #8a6428;
  --black-tile:   #3a2820;
  --black-border: #241810;
  --black-shadow: #120c08;
  --text:         #2a1a0e;
  --text-muted:   #8a7060;
  --cell-empty:   #ddd0b4;
  --cell-border:  #c0a870;
  --cell-active:  #d4c090;
  --success:      #4e7e38;
  --header-bg:    #f7f0e4;
  --header-border:#c49848;
  --bank-bg:      #ddd0b4;
  --bank-inset:   #c8b88c;
}

[data-theme="dark"] {
  --bg:           #1a1a2e;
  --surface:      #16213e;
  --surface-2:    #0f3460;
  --accent:       #a78bfa;
  --accent-2:     #c084fc;
  --tile-bg:      #2d2d4e;
  --tile-border:  #6c5ce7;
  --tile-shadow:  #4c3cb7;
  --black-tile:   #111118;
  --black-border: #333345;
  --black-shadow: #050508;
  --text:         #e8e0ff;
  --text-muted:   #8888bb;
  --cell-empty:   #252545;
  --cell-border:  #4a4a88;
  --cell-active:  #3a3a70;
  --success:      #4ade80;
  --header-bg:    #16213e;
  --header-border:#6c5ce7;
  --bank-bg:      #1e1e38;
  --bank-inset:   #141428;
}

/* ── Reset / Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--header-bg);
  border-bottom: 2px solid var(--header-border);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.3s;
}

.header-inner {
  max-width: 700px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.5px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-link {
  font-weight: 700;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 4px 10px;
  border-radius: 20px;
  transition: background 0.2s, color 0.2s;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--accent);
}

.theme-btn {
  background: var(--surface-2);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.3s;
}

.theme-btn:hover { transform: scale(1.15) rotate(20deg); }

/* ── Main ─────────────────────────────────────────────────────────────────────── */
.main-content {
  max-width: 700px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ── Game layout (outer row: info panel + game column) ───────────────────────── */
.game-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

/* ── Info panel ──────────────────────────────────────────────────────────────── */
.info-panel {
  width: 170px;
  flex-shrink: 0;
  background: var(--surface);
  border-radius: 16px;
  padding: 14px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  position: sticky;
  top: 76px;
  transition: background 0.3s;
}

.info-panel.hidden { display: none; }

.info-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 10px;
}

.info-word-item {
  padding: 5px 0;
  border-bottom: 1px solid var(--cell-border);
  font-weight: 800;
  font-size: 0.95rem;
  font-family: 'Fredoka One', cursive;
  display: flex;
  align-items: center;
  gap: 6px;
}

.info-word-status {
  font-size: 0.75rem;
  line-height: 1;
}

.info-word-solution {
  color: var(--success);
}

.info-word-valid {
  color: var(--text-muted, #888);
}

.info-word-invalid {
  color: #e05050;
}

.info-all-valid {
  color: var(--success);
  font-weight: 800;
  font-size: 0.9rem;
  text-align: center;
  padding: 6px 0;
}

/* ── Submit button ───────────────────────────────────────────────────────────── */
.submit-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 12px 32px;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.18);
  transition: transform 0.12s, box-shadow 0.12s;
  letter-spacing: 0.3px;
}

.submit-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,0.18); }
.submit-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }
.submit-btn.hidden { display: none; }

/* ── Correct tile (forest green) ─────────────────────────────────────────────── */
.tile.correct {
  background: #4e7e38 !important;
  border-color: #355a28 !important;
  box-shadow: 0 4px 0 #1e3818, 0 6px 10px rgba(0,0,0,0.18) !important;
  color: #fff !important;
}

/* ── Last-guessed ghost (shown in empty cell after tile moves away) ──────────── */
.cell-slot[data-last-letter] { position: relative; }

.cell-slot[data-last-letter]:not(.has-tile)::after,
.cell-slot[data-last-letter].tile-lifting::after {
  content: attr(data-last-letter);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Fredoka One', cursive;
  font-size: 1.55rem;
  color: rgba(120, 120, 120, 0.28);
  pointer-events: none;
  z-index: 1;
}

[data-theme="dark"] .cell-slot[data-last-letter]:not(.has-tile)::after,
[data-theme="dark"] .cell-slot[data-last-letter].tile-lifting::after {
  color: rgba(200, 200, 200, 0.22);
}

/* Hide the SortableJS in-place ghost so the letter ghost shows clearly */
.cell-slot.tile-lifting .sortable-ghost {
  opacity: 0;
}

/* ── Confirmed-correct empty slot: soft green glow persists when tile lifts ───── */
.cell-slot[data-confirmed]:not(.has-tile) {
  background: rgba(78, 126, 56, 0.14);
  border-color: rgba(53, 90, 40, 0.35);
  border-style: solid;
}

.cell-slot[data-confirmed]:not(.has-tile)::after {
  color: rgba(53, 90, 40, 0.55);
}

[data-theme="dark"] .cell-slot[data-confirmed]:not(.has-tile) {
  background: rgba(78, 126, 56, 0.12);
  border-color: rgba(100, 180, 70, 0.25);
}

[data-theme="dark"] .cell-slot[data-confirmed]:not(.has-tile)::after {
  color: rgba(100, 180, 70, 0.55);
}

/* ── Mismatch tooltip (only on cells confirmed correct at least once) ────────── */
.tile { position: relative; }

.cell-slot[data-confirmed] .tile.mismatch::before {
  content: attr(data-hint-label);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: #2d1f3d;
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  z-index: 60;
}

.cell-slot[data-confirmed] .tile.mismatch:hover::before { opacity: 1; }

/* ── Game header ─────────────────────────────────────────────────────────────── */
.game-wrapper { display: flex; flex-direction: column; align-items: center; gap: 20px; }

.game-header { text-align: center; }

.game-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2.4rem;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 6px;
}

.game-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
}

.date-badge {
  display: inline-block;
  margin-top: 8px;
  background: var(--surface-2);
  color: var(--accent-2);
  font-weight: 800;
  font-size: 0.85rem;
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

/* ── Status message ──────────────────────────────────────────────────────────── */
.status-msg {
  background: var(--surface-2);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 10px 22px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  text-align: center;
  animation: fadeIn 0.3s ease;
}

.status-msg.success {
  border-color: var(--success);
  color: var(--success);
}

.status-msg.hidden { display: none; }

/* ── Puzzle area ─────────────────────────────────────────────────────────────── */
.puzzle-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 100%;
}

.puzzle-area.horizontal {
  flex-direction: row;
  align-items: flex-start;
  gap: 20px;
}

.puzzle-area.horizontal .bank-section {
  flex: 0 0 auto;
  max-width: none;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
}

.puzzle-area.horizontal .bank {
  order: 1;
  grid-template-columns: repeat(4, 60px);
}

.puzzle-area.horizontal .bank-header {
  order: 2;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 0;
  gap: 10px;
  width: auto;
}

.puzzle-area.horizontal .bank-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}

.puzzle-area.horizontal .bank-actions {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

/* ── Grid ─────────────────────────────────────────────────────────────────────── */
.grid-container {
  background: var(--surface);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
}

.grid {
  border-collapse: separate;
  border-spacing: 6px;
}

.grid-cell {
  padding: 0;
}

.cell-slot {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  border: 2px dashed var(--cell-border);
  background: var(--cell-empty);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  position: relative;
  min-height: 72px;
}

.cell-slot.sortable-drag-over {
  border-color: var(--accent);
  background: var(--cell-active);
  box-shadow: 0 0 0 3px var(--accent);
}

.cell-slot.has-tile {
  border-style: solid;
  border-color: transparent;
  background: transparent;
}

/* ── Bank ─────────────────────────────────────────────────────────────────────── */
.bank-section {
  width: 100%;
  max-width: 340px;
}

.bank-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}

.bank-label {
  font-weight: 800;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.bank-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.bank-ctrl-btn {
  background: var(--surface-2);
  border: 1.5px solid var(--cell-border);
  border-radius: 10px;
  padding: 3px 9px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, transform 0.12s;
  white-space: nowrap;
}

.bank-ctrl-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.bank {
  background: var(--bank-bg);
  border-radius: 18px;
  padding: 14px 12px;
  box-shadow: inset 0 3px 8px rgba(0,0,0,0.12);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

/* ── Tiles ─────────────────────────────────────────────────────────────────────── */
.tile {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka One', cursive;
  font-size: 1.7rem;
  cursor: grab;
  user-select: none;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  flex-shrink: 0;
}

.tile:active { cursor: grabbing; }

.tile.letter-tile {
  background: var(--tile-bg);
  border: 2px solid var(--tile-border);
  box-shadow: 0 4px 0 var(--tile-shadow), 0 6px 8px rgba(0,0,0,0.12);
  color: var(--text);
}

.tile.black-tile {
  background: var(--black-tile);
  border: 2px solid var(--black-border);
  box-shadow: 0 4px 0 var(--black-shadow), 0 6px 8px rgba(0,0,0,0.20);
  color: transparent;
  font-size: 0;
}

.tile.black-tile::after {
  content: '■';
  font-size: 1.4rem;
  color: rgba(255,255,255,0.15);
  font-family: sans-serif;
}

.tile:hover {
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 7px 0 var(--tile-shadow), 0 10px 16px rgba(0,0,0,0.15);
}

.tile.letter-tile:hover {
  box-shadow: 0 7px 0 var(--tile-shadow), 0 10px 16px rgba(0,0,0,0.15);
}

/* Pop animation when tile lands in a cell */
@keyframes tilePop {
  0%   { transform: scale(1.18); }
  60%  { transform: scale(0.95); }
  100% { transform: scale(1.0); }
}

.tile.just-placed {
  animation: tilePop 0.22s ease forwards;
}

/* Success pulse on grid */
@keyframes cellGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(92,184,92,0); }
  50%       { box-shadow: 0 0 0 6px rgba(92,184,92,0.45); }
}

.cell-slot.solved {
  animation: cellGlow 0.8s ease 2;
  border-style: solid;
  border-color: var(--success);
}

/* ── Bank slot (same shape as grid cell) ────────────────────────────────────── */
.bank-slot {
  width: auto;
  min-width: 60px;
  height: 68px;
  min-height: 68px;
}

/* ── Ghost tile (typed but not in bank) ──────────────────────────────────────── */
.ghost-tile {
  opacity: 0.5;
  border-style: dashed !important;
}

/* ── Typing mode styles ──────────────────────────────────────────────────────── */
.cell-slot.typing-run {
  background: rgba(167, 139, 250, 0.10);
  border-color: rgba(167, 139, 250, 0.45);
  border-style: solid;
}

.cell-slot.typing-cursor {
  background: var(--cell-active);
  border-color: var(--accent);
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.40);
}

[data-theme="light"] .cell-slot.typing-run {
  background: rgba(255, 107, 107, 0.07);
  border-color: rgba(255, 107, 107, 0.35);
}

[data-theme="light"] .cell-slot.typing-cursor {
  background: #ffe8e8;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.25);
}

.typing-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 2px solid var(--accent);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  animation: fadeIn 0.2s ease;
}

.dir-label {
  color: var(--accent);
  font-size: 1rem;
  min-width: 80px;
}

.typing-hint {
  color: var(--text-muted);
  font-weight: 600;
}

.typing-bar.hidden { display: none; }

/* ── Instructions ────────────────────────────────────────────────────────────── */
.instructions {
  max-width: 380px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
  font-weight: 600;
}

/* ── Archive ──────────────────────────────────────────────────────────────────── */
.archive-wrapper {
  max-width: 640px;
  margin: 0 auto;
}

.page-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  color: var(--accent);
  margin-bottom: 6px;
}

.archive-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 24px;
}

.archive-loading {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  font-weight: 700;
}

/* ── Calendar layout ──────────────────────────────────────────────────────────── */
.calendar-container {
  display: flex;
  flex-direction: column;
  gap: 44px;
}

.cal-month-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.25rem;
  color: var(--text);
  margin-bottom: 10px;
}

.cal-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}

.cal-dow-label {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--text-muted);
  padding: 4px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day {
  position: relative;
  height: 58px;
  border-radius: 10px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 2px solid transparent;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  overflow: visible;
}

.cal-day-pad {
  background: transparent !important;
  border: none !important;
  pointer-events: none;
}

.cal-unavail {
  opacity: 0.28;
  pointer-events: none;
}

.cal-day:not(.cal-unavail):not(.cal-day-pad) {
  cursor: pointer;
}

.cal-day:not(.cal-unavail):not(.cal-day-pad):hover {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-2px);
  z-index: 10;
}

.cal-today {
  border-color: var(--accent-2) !important;
}

.cal-num {
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1;
}

.cal-tick {
  font-size: 0.7rem;
  font-weight: 900;
  color: var(--success);
  line-height: 1;
}

/* ── Puzzle hover preview ─────────────────────────────────────────────────────── */
.puzzle-preview {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  gap: 5px;
  background: var(--surface);
  border: 2px solid var(--cell-border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.24);
  z-index: 300;
  pointer-events: none;
  white-space: nowrap;
}

.cal-day.has-preview:hover .puzzle-preview {
  display: flex;
}

.prev-row {
  display: flex;
  gap: 5px;
}

.prev-cell {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  line-height: 1;
  font-weight: 700;
}

.prev-letter {
  background: var(--tile-bg);
  color: var(--text);
  border: 1.5px solid var(--tile-border);
}

.prev-cell-sm {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  font-size: 0.75rem;
}

.prev-black {
  background: var(--black-tile);
}

/* ── Solution reveal ─────────────────────────────────────────────────────────── */
.solution-overlay { display: block; }
.solution-overlay.hidden { display: none; }

.solution-toggle-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--cell-border);
  border-radius: 14px;
  padding: 10px 24px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.12s;
  letter-spacing: 0.3px;
}

.solution-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
}

/* ── SortableJS ghost + drag ─────────────────────────────────────────────────── */
.sortable-ghost {
  opacity: 0.35;
}

.sortable-chosen {
  transform: scale(1.08);
}

/* ── Animations ──────────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Mode sidebar ────────────────────────────────────────────────────────────── */
.mode-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: 76px;
  height: 100vh;
  background: var(--surface);
  border-right: 2px solid var(--header-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 72px;
  gap: 6px;
  z-index: 50;
  transition: background 0.3s;
}

.mode-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-muted);
  padding: 10px 6px;
  border-radius: 12px;
  width: 62px;
  transition: background 0.18s, color 0.18s;
  text-align: center;
}

.mode-link:hover { background: var(--surface-2); color: var(--accent); }
.mode-link-active { background: var(--surface-2); color: var(--accent); }

.mode-size {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  line-height: 1;
  letter-spacing: 0.5px;
}

.mode-label {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
}

body { padding-left: 76px; }

/* ── 5×5 bank grid ───────────────────────────────────────────────────────────── */
.bank.bank-5x5 {
  grid-template-columns: repeat(5, 1fr);
}

.puzzle-area.horizontal .bank.bank-5x5 {
  grid-template-columns: repeat(5, 60px);
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  body { padding-left: 0; padding-top: 46px; }

  .mode-sidebar {
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 46px;
    flex-direction: row;
    justify-content: center;
    padding: 0 12px;
    padding-top: 0;
    gap: 6px;
    border-right: none;
    border-bottom: 2px solid var(--header-border);
    position: fixed;
    z-index: 90;
  }

  .site-header { top: 46px; }

  .mode-link {
    flex-direction: row;
    gap: 6px;
    width: auto;
    padding: 6px 10px;
  }

  .game-layout { flex-direction: column; align-items: center; }
  .info-panel { width: 100%; max-width: 400px; position: static; order: 2; }
  .game-wrapper { order: 1; }
}

@media (max-width: 480px) {
  .cell-slot { width: 60px; height: 60px; min-height: 60px; }
  .bank-slot { height: 64px; min-height: 64px; }
  .tile { width: 52px; height: 52px; font-size: 1.4rem; }
  .game-title { font-size: 1.9rem; }
}
