:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f6f7f8;
  --text: #1a1a1b;
  --muted: #787c7e;
  --border: #d3d6da;
  --tile: #ffffff;
  --tile-border: #d3d6da;
  --green: #6aaa64;
  --yellow: #c9b458;
  --grey: #787c7e;
  --button: #818384;
  --button-text: #ffffff;
  --shadow: rgba(0,0,0,0.08);
  --row-gap: 6px;
  --tile-size: min(13.5vw, 64px);
  --tile-gap: 6px;
  --board-content-width: calc((5 * var(--tile-size)) + (4 * var(--tile-gap)) + 24px);
}

html.theme-dark, body.theme-dark {
  --bg: #121213;
  --panel: #1b1b1d;
  --panel-2: #222326;
  --text: #f8f8f8;
  --muted: #a0a4ab;
  --border: #3a3a3c;
  --tile: #121213;
  --tile-border: #565758;
  --green: #6aaa64;
  --yellow: #c9b458;
  --grey: #3a3a3c;
  --button: #818384;
  --button-text: #ffffff;
  --shadow: rgba(0,0,0,0.28);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; min-height: 100vh; }
body.theme-animating { transition: background-color 320ms ease, color 320ms ease; }
.app { width: fit-content; max-width: 100%; margin: 0 auto; padding: 20px; display: grid; grid-template-columns: 320px auto; gap: 24px; align-items: start; }
.panel, .board-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 12px 30px var(--shadow); }
body.theme-animating .panel, body.theme-animating .board-wrap { transition: background-color 320ms ease, border-color 320ms ease, box-shadow 320ms ease; }
.panel { padding: 20px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 16px; }
.panel-top, .panel-bottom { display: flex; flex-direction: column; gap: 18px; }
.title-bar { display: flex; align-items: center; justify-content: flex-start; position: relative; }
.title-line { display: flex; align-items: baseline; gap: 10px; }
.day-number { color: var(--text); font-size: 1.44rem; letter-spacing: 0.04em; font-style: normal; font-weight: 400; opacity: 0.9; }
.board-title-bar { margin-bottom: 12px; padding-right: 28px; }
h1 { margin: 0; font-size: 2.15rem; letter-spacing: 0.08em; font-weight: 800; }
.tag { color: var(--muted); line-height: 1.45; font-size: 0.97rem; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--panel-2); border-radius: 14px; padding: 12px; border: 1px solid var(--border); }
.stat-label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.stat-value { font-size: 1.35rem; font-weight: 800; }
.stat.swaps-stat { border-color: rgba(201,180,88,0.28); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--yellow) 18%, transparent); }
.stat.swaps-stat .stat-label { color: color-mix(in srgb, var(--yellow) 85%, var(--text)); }
.stat.swaps-stat .stat-value { font-size: 2.1rem; line-height: 1; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; }
.icon-btn { width: 28px; height: 28px; padding: 0; border: 0; border-radius: 0; display: inline-grid; place-items: center; background: transparent; box-shadow: none; color: var(--muted); font-size: 1rem; line-height: 1; }
.icon-btn:hover, .icon-btn:active { transform: none; background: transparent; }
.icon-btn:hover { color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; display: block; fill: currentColor; }
button { border: 2px solid var(--border); border-radius: 10px; padding: 11px 15px; font-size: 0.95rem; font-weight: 800; cursor: pointer; background: var(--button); color: var(--button-text); box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12); transition: transform 120ms ease, opacity 120ms ease; }
body.theme-animating button { transition: transform 120ms ease, opacity 120ms ease, background-color 240ms ease, color 240ms ease, border-color 240ms ease; }
button:hover { transform: translateY(-1px); } button:active { transform: translateY(1px); }
.secondary-btn { background: var(--panel-2); color: var(--text); border-color: var(--border); box-shadow: none; }
.panel-actions { display: flex; justify-content: flex-start; }
#shareBtn { background: var(--green); border-color: var(--green); color: #fff; }
#playAgainBtn { background: var(--yellow); border-color: var(--yellow); color: #fff; }
.legend { display: grid; gap: 8px; font-size: 0.94rem; color: var(--muted); }
.legend-row { display: flex; gap: 10px; align-items: center; }
.legend-tile { width: 20px; height: 20px; border-radius: 4px; border: 2px solid rgba(255,255,255,0.08); flex: 0 0 auto; }
.board-wrap { padding: 20px; width: auto; max-width: 100%; position: relative; overflow-x: hidden; }
.board-bottom { margin-top: 10px; display: grid; grid-template-columns: auto; gap: 10px; align-items: start; width: var(--board-content-width); max-width: 100%; }
.board-bottom.finish-mode { grid-template-columns: 1fr; }
.board-meta-full { display: grid; min-height: 1.4em; width: var(--board-content-width); max-width: 100%; align-items: center; margin-top: 10px; }
.board-swaps-card { display: inline-flex; flex-direction: column; justify-content: center; align-items: center; min-width: 104px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; box-shadow: inset 0 0 0 1px transparent; }
.board-swaps-card.good { background: color-mix(in srgb, var(--green) 16%, var(--panel-2)); border-color: color-mix(in srgb, var(--green) 55%, var(--border)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--green) 25%, transparent); }
.board-swaps-card.mid { background: color-mix(in srgb, var(--yellow) 16%, var(--panel-2)); border-color: color-mix(in srgb, var(--yellow) 55%, var(--border)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--yellow) 25%, transparent); }
.board-swaps-card.bad { background: color-mix(in srgb, #e05d5d 16%, var(--panel-2)); border-color: color-mix(in srgb, #e05d5d 55%, var(--border)); box-shadow: inset 0 0 0 1px color-mix(in srgb, #e05d5d 25%, transparent); }
.board-swaps-card[hidden] { display: none; }
.board-swaps-label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; text-align:center; }
.swap-icon { font-size: 1.125em; line-height: 1; opacity: 0.95; display:block; }
.board-swaps-value { font-size: 2.32rem; font-weight: 900; line-height: 1; display:flex; align-items:center; justify-content:center; gap:8px; width:100%; min-height: 2.5rem; }
.goal-text { color: var(--muted); font-size: 0.82rem; line-height: 1.25; opacity: 0.88; text-align: center; max-width: 100%; }
.goal-text-footer { width: var(--board-content-width); max-width: 100%; margin-top: 8px; justify-self: center; }
.message { color: var(--muted); min-height: 1.4em; font-size: 0.95rem; text-align: center; }
.message.teaching-emphasis { font-weight: 800; color: color-mix(in srgb, var(--text) 78%, var(--muted) 22%); }
.teaching-hint-tile { position: relative; animation: teachingHintPulse 1.1s ease-in-out 2; box-shadow: 0 0 0 3px rgba(201,180,88,0.22); }
.teaching-hint-swap { position: absolute; top: 50%; transform: translate(-50%, -50%); font-size: 1.2rem; font-weight: 800; color: var(--text); background: color-mix(in srgb, var(--panel) 88%, transparent); padding: 2px 6px; border-radius: 999px; pointer-events: none; animation: teachingHintBob 1.1s ease-in-out 2; z-index: 4; }
.teaching-hint-swap.vertical { transform: translate(-50%, 0); }
.teaching-hint-swap.vertical.long { transform: translate(-50%, -50%); }
.teaching-hint-swap.vertical.long.floating { position: absolute; }
@keyframes teachingHintPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.045); } }
@keyframes teachingHintBob { 0%,100% { opacity: 0.0; transform: translate(-50%, -50%) translateY(4px); } 25%,75% { opacity: 1; transform: translate(-50%, -50%) translateY(0); } }
#soundBtn { position: absolute; right: 0; top: 50%; transform: translateY(-50%); z-index: 3; }
.rows { display: grid; gap: var(--row-gap); justify-content: start; width: var(--board-content-width); max-width: 100%; position: relative; }
.row { background: var(--panel-2); border: 1px solid var(--border); border-radius: 16px; padding: 10px 12px; display: inline-grid; grid-template-columns: auto; align-items: center; gap: 12px; width: fit-content; max-width: 100%; position: relative; }
.tiles { display: grid; grid-template-columns: repeat(5, var(--tile-size)); gap: var(--tile-gap); }
.tile { width: var(--tile-size); height: var(--tile-size); border-radius: 8px; border: 2px solid var(--tile-border); background: var(--tile); color: var(--text); display: grid; place-items: center; font-size: clamp(1.25rem, 3vw, 2rem); font-weight: 800; text-transform: uppercase; user-select: none; touch-action: none; position: relative; transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease; -webkit-user-select: none; }
body.theme-animating .tile { transition: transform 120ms ease, border-color 240ms ease, box-shadow 120ms ease, background-color 280ms ease, color 280ms ease, opacity 120ms ease; }
.tile.green { background: var(--green); border-color: var(--green); color: #fff; }
.tile.yellow { background: var(--yellow); border-color: var(--yellow); color: #fff; }
.tile.grey { background: var(--grey); border-color: var(--grey); color: #fff; }
.tile.selected { box-shadow: 0 0 0 3px rgba(255,255,255,0.18); transform: scale(1.04); z-index: 2; }
@media (hover: hover) and (pointer: fine) {
  .tile.hovered { box-shadow: 0 0 0 3px rgba(0,0,0,0.28), inset 0 0 0 2px rgba(255,255,255,0.92); }
  .tile.green.hovered, .tile.yellow.hovered, .tile.grey.hovered { box-shadow: 0 0 0 3px rgba(0,0,0,0.28), inset 0 0 0 2px rgba(255,255,255,0.96); }
  html.theme-dark .tile.hovered, body.theme-dark .tile.hovered { box-shadow: 0 0 0 3px rgba(255,255,255,0.16), inset 0 0 0 2px rgba(255,255,255,0.9); }
  html.theme-dark .tile.green.hovered, html.theme-dark .tile.yellow.hovered, html.theme-dark .tile.grey.hovered, body.theme-dark .tile.green.hovered, body.theme-dark .tile.yellow.hovered, body.theme-dark .tile.grey.hovered { box-shadow: 0 0 0 3px rgba(255,255,255,0.16), inset 0 0 0 2px rgba(255,255,255,0.9); }
}
.tile.drag-source { opacity: 0.28; transform: scale(0.98); }
.tile.drop-target { box-shadow: 0 0 0 3px rgba(255,255,255,0.24), 0 0 20px rgba(255,255,255,0.12); transform: scale(1.06); z-index: 2; }
.tile.solved { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.12); }
.tile.green.solved { box-shadow: none; }
.drag-ghost { position: fixed; width: var(--tile-size); height: var(--tile-size); border-radius: 8px; border: 2px solid rgba(255,255,255,0.22); color: #fff; display: grid; place-items: center; font-size: clamp(1.25rem, 3vw, 2rem); font-weight: 800; text-transform: uppercase; pointer-events: none; z-index: 9999; transform: translate(-50%, -50%) scale(1.08); box-shadow: 0 16px 30px rgba(0,0,0,0.35); }
.drag-ghost.green { background: var(--green); border-color: var(--green); color:#fff; }
.drag-ghost.yellow { background: var(--yellow); border-color: var(--yellow); color:#fff; }
.drag-ghost.grey { background: var(--grey); border-color: var(--grey); color:#fff; }
.row.solved { border-color: rgba(106,170,100,0.42); background: color-mix(in srgb, var(--green) 10%, var(--panel)); box-shadow: inset 0 0 0 1px rgba(106,170,100,0.12); }
.row.solved .tiles { opacity: 0.96; }
.row.solved .tile { cursor: default; }
.row.solved .tile.yellow, .row.solved .tile.grey { filter: saturate(0.92) brightness(0.98); }
html.theme-dark .row.solved, body.theme-dark .row.solved { background: color-mix(in srgb, var(--green) 14%, var(--panel)); box-shadow: inset 0 0 0 1px rgba(106,170,100,0.16); }
.footer { color: var(--muted); font-size: 0.92rem; line-height: 1.5; }
.meta-footer { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.82rem; opacity: 0.9; }
.meta-footer a { color: var(--muted); text-decoration: none; }
.meta-footer a:hover { color: var(--text); text-decoration: underline; }
.lang-links { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.lang-links .sep { opacity: 0.55; }
.solved-panel { margin-top: 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; text-align: center; width: var(--board-content-width); max-width: 100%; min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.solved-panel[hidden] { display: none; }
.solved-panel h2 { margin: 0 0 6px; font-size: 1.42rem; letter-spacing: 0.04em; }
.solved-actions { display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }
.next-daily-panel { margin-top: 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; text-align: center; width: var(--board-content-width); max-width: 100%; min-width: 0; }
.next-daily-panel[hidden] { display: none; }
.next-daily-text { font-size: 1rem; font-weight: 400; color: var(--muted); line-height: 1.4; }
.next-daily-emphasis { color: var(--text); font-weight: 800; }
.toast { position: fixed; left: 0; top: 0; transform: translate(-50%, calc(-100% - 10px)) translateY(8px); background: rgba(26,26,27,0.92); color: #fff; border-radius: 999px; padding: 10px 14px; font-size: 0.92rem; font-weight: 700; z-index: 10000; opacity: 0; pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, calc(-100% - 10px)) translateY(0); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: grid; place-items: center; padding: 20px; z-index: 9998; }
.modal-backdrop[hidden] { display: none; }
.modal-card { width: min(100%, 420px); background: var(--panel); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 18px 40px rgba(0,0,0,0.28); padding: 16px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.modal-header h2 { margin: 0; font-size: 1.28rem; letter-spacing: 0.03em; }
.stats-grid { display: grid; gap: 14px; }
.stats-section { display: grid; gap: 10px; }
.stats-section-title { margin: 0; font-size: 0.88rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stats-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stats-label { color: var(--muted); font-size: 0.92rem; }
.stats-value { font-size: 1.1rem; font-weight: 800; color: var(--text); text-align: right; }
.win-summary { display: grid; gap: 8px; color: var(--muted); line-height: 1.4; margin-bottom: 14px; width: 100%; max-width: 100%; min-width: 0; justify-items: stretch; }
.win-summary > div { width: 100%; max-width: 100%; min-width: 0; white-space: normal; }
@keyframes swapScoreGradientShift {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}
.swap-score {
  font-weight: 900;
  font-size: 1.32em;
  color: var(--green);
}
.swap-score.genius {
  background: linear-gradient(90deg, #6aaa64 0%, #2ec4b6 50%, #3ddc97 100%);
  background-size: 200% 100%;
  background-position: 0% 50%;
  -webkit-background-clip: text;
  background-clip: text;
  color: #2ec4b6;
  -webkit-text-fill-color: transparent;
  animation: swapScoreGradientShift 5.5s linear infinite;
}
.swap-score.good { color: var(--green); }
.swap-score.mid { color: var(--yellow); }
.swap-score.bad { color: #e05d5d; }
@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .panel { position: static; order: 1; }
  .board-wrap { order: 1; }
  .panel-bottom { order: 2; }
}
@media (max-width: 560px) {
  body { padding-top: 10px; }
  .app { width: 100%; padding: 12px; gap: 12px; display: flex; flex-direction: column; --board-content-width: 100%; }
  .panel, .board-wrap { width: 100%; border-radius: 16px; }
  .panel { display: contents; }
  .panel-bottom, .board-wrap { width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 12px 30px var(--shadow); padding: 16px; }
  .board-wrap { box-shadow: 0 16px 36px rgba(0,0,0,0.34); border-color: var(--border); width: 100%; max-width: none; padding: 14px; }
  .panel-bottom { gap: 12px; }
  h1 { font-size: 1.9rem; text-align: left; }
  .title-bar { min-height: 36px; }
  .title-line { gap: 8px; }
  .day-number { font-size: 1rem; }
  .tag { font-size: 0.95rem; line-height: 1.35; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .controls { justify-content: flex-start; }
  .rows { display: flex; flex-direction: column; width: 100%; align-items: stretch; }
  .row { display: block; width: 100%; max-width: none; padding: 6px 8px; border-radius: 14px; }
  .tiles { display: grid; justify-content: stretch; grid-template-columns: repeat(5, minmax(0, 1fr)); width: 100%; }
  .tile { width: 100%; height: min(17vw, 62px); min-height: 50px; border-radius: 7px; }
  .board-bottom { margin-top: 8px; grid-template-columns: auto; gap: 10px; justify-content: center; }
  .board-bottom.finish-mode { grid-template-columns: 1fr; }
  .board-swaps-card { min-width: 104px; width: auto; justify-self: center; padding: 8px 10px; }
  .board-swaps-label { font-size: 0.66rem; margin-bottom: 3px; }
  .board-swaps-value { font-size: 1.5rem; }
  .message { font-size: 0.82rem; line-height: 1.25; opacity: 0.88; text-align: center; }
  .goal-text { font-size: 0.78rem; }
  #soundBtn { top: 50%; right: 0; }
  .footer { font-size: 0.88rem; line-height: 1.35; }
  .solved-panel { padding: 14px; }
  .solved-panel h2 { font-size: 1.35rem; }
  .win-summary { gap: 8px; }
}

.title-actions { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display:flex; gap:8px; align-items:center; }
#soundBtn, #themeBtn { position: static; transform:none; }
