:root {
  --page-bg: #f4f4f6;
  --panel-bg: #fafafa;
  --cell-bg: #ffffff;
  --slot-bg: #f1f1f1;
  --tile-bg: #f4e29a;
  --tile-bg-hover: #ffe7a8;
  --tile-neutral-bg: #ffffff;
  --tile-neutral-bg-hover: #fbfbfb;
  --text: #222;
  --muted: #666;
  --border: #ddd;
  --border-light: #ddd;
  --accent: #42a5f5;
  --bonus-1: #f4e29a;
  --bonus-2: #a7bfdc;
  --bonus-3: #e2a6a0;
  --danger: #c62828;
  --shadow: none;
  --game-width: min(calc(100vw - 16px), 348px);
  --tile-size: clamp(34px, 12.2vw, 48px);
  --tile-gap: 2px;
  --row-height: clamp(42px, 8svh, 56px);
  --rank-frame-padding: 6px;
  --control-size: 42px;
  --submission-gap: 8px;
  --top-bar-height: min(44px, calc(var(--row-height) * 0.92));
  --score-gap: 10px;
}

body.theme-dark {
  --page-bg: #111;
  --panel-bg: #1a1a1a;
  --cell-bg: #222;
  --slot-bg: #f1f1f1;
  --text: #eee;
  --muted: #a9a9a9;
  --border: #444;
  --border-light: #ddd;
  --accent: #4fc3f7;
  --danger: #ff8a80;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

html {
  height: var(--visible-vh, 100dvh);
  min-height: var(--visible-vh, 100dvh);
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  width: 100%;
  height: var(--visible-vh, 100dvh);
  min-height: var(--visible-vh, 100dvh);
  margin: 0;
  padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
  background: var(--page-bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  border: 5px solid transparent;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button,
input,
.hud-button,
.bank-tile,
.letter-tile,
.click-to-submit,
.click-to-exchange,
.click-to-shuffle,
.click-to-undo {
  touch-action: manipulation;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

#confettiLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}

.share-toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 80;
  width: min(calc(100vw - 32px), 340px);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.2s ease;
}

.share-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.share-toast.hidden {
  display: none;
}

.confetti-piece {
  position: absolute;
  width: 6px;
  height: 10px;
  background: var(--bonus-1);
  opacity: 0.9;
  pointer-events: none;
  animation-name: confetti-fall;
  animation-timing-function: ease-out;
  animation-fill-mode: forwards;
}

.meter-star-particle {
  position: fixed;
  z-index: 55;
  color: #f9a825;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: meter-star-shower 0.82s cubic-bezier(0.17, 0.84, 0.31, 1) forwards;
}

a,
a:visited {
  color: var(--tile-bg);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover,
a:active {
  color: var(--tile-bg-hover);
}

h1 {
  margin: 0;
  min-width: 0;
  font-size: clamp(1.18rem, 5.4vw, 1.75rem);
  line-height: 0.92;
  letter-spacing: 0.055em;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

#header-container,
#puzzle-container,
#letter-tray {
  width: var(--game-width);
}

.header-row,
.puzzle-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

#top-bar {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: var(--game-width);
  height: var(--top-bar-height);
  min-height: var(--top-bar-height);
  margin-bottom: 0;
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 68px;
  align-items: center;
  gap: 6px;
}

#top-bar,
#header-container,
#puzzle-container,
#letter-tray,
#submission {
  flex-shrink: 0;
}

.top-hud {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.top-hud-right {
  justify-content: flex-end;
}

.hud-button {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font: inherit;
}

.hud-button:hover,
.hud-button:focus-visible {
  background: #fff;
  border-color: #ccc;
  outline: none;
}

body.theme-dark .hud-button:hover,
body.theme-dark .hud-button:focus-visible {
  background: #222;
  border-color: #666;
}

.hud-button .material-symbols-outlined,
.hud-glyph {
  font-size: 22px;
  line-height: 1;
}

.hud-glyph {
  font-weight: 800;
}

.hud-star {
  color: #f9a825;
  font-size: 19px;
}

.hamburger {
  flex-direction: column;
  gap: 4px;
}

.hamburger span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.hamburger.open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.hamburger.open span:nth-child(2) {
  opacity: 0;
}

.hamburger.open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.menu-dropdown {
  position: absolute;
  top: 50px;
  left: 0;
  z-index: 20;
  min-width: 160px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-dropdown.hidden {
  display: none;
}

.menu-dropdown button {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: #222;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  text-align: left;
}

body.theme-dark .menu-dropdown button {
  background: #fff;
  color: #222;
}

.menu-dropdown button:hover {
  background: var(--tile-bg);
}

.menu-icon {
  display: inline-block;
  min-width: 1.5em;
  margin-right: 6px;
  text-align: center;
  font-weight: 800;
}

#header-container {
  margin-top: calc(var(--top-bar-height) + clamp(3px, calc(var(--row-height) * 0.08), 8px));
  margin-bottom: clamp(3px, calc(var(--row-height) * 0.08), 8px);
}

#header,
#header-container,
.header-row {
  width: var(--game-width);
}

.header-row {
  min-height: min(44px, var(--row-height));
  display: block;
}

#header .round-number,
#header .score-field {
  display: none;
}

#header .puzzle-field {
  width: var(--game-width);
  min-width: var(--game-width);
  max-width: var(--game-width);
  min-height: 40px;
  display: block;
}

.round-number {
  width: 24px;
  flex: 0 0 24px;
  margin-left: 4px;
  color: var(--muted);
  font-size: 18px;
  text-align: right;
}

.puzzle-field {
  --word-inner-width: calc(var(--game-width) - 24px - 34px - var(--score-gap) - 8px);
  flex: 1;
  min-width: 0;
  min-height: var(--row-height);
  display: flex;
  align-items: center;
  justify-content: center;
}

#rank-frame .puzzle-field {
  --word-inner-width: calc(var(--game-width) - 12px - 10px - 34px - var(--score-gap) - 8px);
  margin-left: 10px;
}

#rank-frame .round-number {
  display: none;
}

#puzzle-container > .puzzle-row:first-child {
  position: relative;
}

#puzzle-container > .puzzle-row:first-child .round-number,
#puzzle-container > .puzzle-row:first-child .score-field {
  display: none;
}

#puzzle-container > .puzzle-row:first-child .puzzle-field {
  --word-inner-width: var(--game-width);
  width: 100%;
  flex: 0 0 100%;
}

.score-field {
  width: 34px;
  flex: 0 0 34px;
  margin-right: 4px;
  margin-left: var(--score-gap);
  display: flex;
  align-items: center;
  justify-content: center;
}

#puzzle-container {
  padding: 0;
}

.puzzle-row {
  min-height: var(--row-height);
}

#rank-frame {
  padding: var(--rank-frame-padding);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
}

#puzzle-container > .puzzle-row:first-child {
  margin-bottom: clamp(3px, calc(var(--row-height) * 0.08), 8px);
}

.puzzle-field p {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--word-inner-width);
  max-width: var(--word-inner-width);
  min-height: var(--tile-size);
  gap: var(--tile-gap);
  margin: 0;
  text-align: center;
}

.material-symbols-rounded {
  color: #b0b0b0 !important;
}

.progress-wrapper,
.progress-container,
.progress-overlay {
  width: var(--game-width);
  min-width: var(--game-width);
  max-width: var(--game-width);
}

.progress-wrapper {
  position: relative;
  height: 52px;
  margin-left: 0;
  display: flex;
  align-items: flex-start;
  padding-top: 9px;
}

.progress-container {
  position: relative;
  width: calc(var(--game-width) - 20px);
  min-width: calc(var(--game-width) - 20px);
  max-width: calc(var(--game-width) - 20px);
  height: 22px;
  margin-left: 20px;
  overflow: visible;
  z-index: 1;
  border: 1px solid #cfcfcf;
  border-radius: 7px;
  background: #fff;
}

body.theme-dark .progress-container {
  border-color: #444;
  background: #fff;
}

.progress-overlay {
  position: absolute;
  inset: 0;
  height: 40px;
  z-index: 2;
  pointer-events: none;
}

.progress-bar {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: visible;
  border-radius: 6px;
  background: #fff;
}

body.theme-dark .progress-bar {
  background: #fff;
}

.circle {
  position: absolute;
  top: 20px;
  left: 0;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  color: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-50%);
  font-size: 23px;
  font-weight: 800;
}

body.theme-dark .circle {
  background: #fff;
  color: #222;
}

.total-score {
  margin: 0;
  color: inherit;
  font-size: 1em;
  line-height: 1;
  text-align: center;
}

.total-score.score-3-digits {
  font-size: 0.72em;
}

.total-score.score-4-digits {
  font-size: 0.58em;
}

.block {
  position: absolute;
  top: 0;
  bottom: 0;
  display: inline-block;
  animation: progress-bar-animation 0.3s ease-in-out;
}

.colour-1 {
  background: var(--bonus-1);
}

.colour-2 {
  background: var(--bonus-2);
}

.colour-3 {
  background: var(--bonus-3);
}

.notch {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: 1px;
  background: #aaa;
}

.notch-best {
  width: 1px;
  background: #222;
}

body.theme-dark .notch-best {
  background: #fff;
}

.notch-50 {
  left: 45%;
}

.notch-75 {
  left: 68%;
}

.notch-100 {
  left: 91%;
}

.label {
  position: absolute;
  top: 24px;
  z-index: 20;
  width: 40px;
  color: #777;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.label.meter-star-earned {
  top: -15px;
  color: #f9a825;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: -1px;
  animation: win-star-pop 0.48s cubic-bezier(0.22, 1.08, 0.3, 1) forwards;
}

.label.meter-hs-marker {
  top: -14px;
  color: #555;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

p#score-word1,
p#score-word2,
p#score-word3,
p#score-word4,
p#score-word5 {
  width: 32px;
  height: 32px;
  margin: 0;
  border-radius: 6px;
  color: #1d1d1d;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 32px;
  text-align: center;
  font-size: clamp(14px, 3vw, 22px);
  font-weight: 600;
}

p.scoreBonus0 {
  background: #dedede;
  color: #555;
}

p.score-provisional {
  background: #dedede;
  color: #555;
  font-weight: 500;
}

p.scoreBonus1 {
  background: var(--bonus-1);
}

p.scoreBonus2 {
  background: var(--bonus-2);
}

p.scoreBonus3 {
  background: var(--bonus-3);
}

#letter-bank {
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--tile-gap);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

#letter-tray #letter-bank {
  flex-wrap: nowrap;
  --bank-inner-width: var(--game-width);
}

#letter-tray {
  min-height: calc(var(--tile-size) + 6px);
  margin-top: clamp(3px, calc(var(--row-height) * 0.08), 8px);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#letter-tray.letter-tray-endgame {
  min-height: 156px;
  align-items: stretch;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
}

.tray-message {
  width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.tray-message-win {
  overflow: hidden;
}

.win-sequence {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.win-sequence-line {
  opacity: 0;
  transform: translateY(10px) scale(0.96);
}

.win-sequence-line.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  transition:
    opacity 0.3s ease-out,
    transform 0.4s cubic-bezier(0.2, 1.1, 0.24, 1);
}

.win-sequence-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.05;
  text-transform: uppercase;
}

.win-sequence-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 24px;
}

.win-sequence-star {
  opacity: 0;
  transform: translateY(14px) scale(0);
  display: inline-block;
  color: #f9a825;
  font-size: 22px;
  line-height: 1;
}

.win-sequence-star.is-visible {
  animation: win-star-pop 0.54s cubic-bezier(0.22, 1.08, 0.3, 1) forwards;
}

.win-sequence-no-stars,
.win-sequence-time {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.tray-action-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}

.tray-action-button {
  min-width: 92px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: #1b1b1b;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  opacity: 1;
}

.tray-action-button.reveal-on-win {
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 0.25s ease,
    transform 0.32s ease,
    background-color 0.18s ease,
    border-color 0.18s ease;
}

.tray-action-button.reveal-on-win.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.tray-action-button:hover {
  background: var(--tile-bg);
  border-color: #cccccc;
}

.letter-tile,
.bank-tile {
  position: relative;
  width: min(var(--tile-size), calc((var(--word-inner-width) - ((var(--tile-count, 7) - 1) * var(--tile-gap))) / var(--tile-count, 7)));
  height: min(var(--tile-size), calc((var(--word-inner-width) - ((var(--tile-count, 7) - 1) * var(--tile-gap))) / var(--tile-count, 7)));
  min-width: 18px;
  min-height: 18px;
  margin: 0;
  border-radius: 6px;
  background: var(--tile-neutral-bg);
  color: #222;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(15px, calc(min(var(--tile-size), calc((var(--word-inner-width) - ((var(--tile-count, 7) - 1) * var(--tile-gap))) / var(--tile-count, 7))) * 0.62), 30px);
  font-weight: 800;
  line-height: 1;
  user-select: none;
  border: 1px solid #d8d8d8;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    opacity 0.16s ease,
    transform 0.16s ease;
}

#letter-tray .bank-tile {
  width: min(var(--tile-size), calc((var(--bank-inner-width) - ((var(--tile-count, 7) - 1) * var(--tile-gap))) / var(--tile-count, 7)));
  height: min(var(--tile-size), calc((var(--bank-inner-width) - ((var(--tile-count, 7) - 1) * var(--tile-gap))) / var(--tile-count, 7)));
  font-size: clamp(15px, calc(min(var(--tile-size), calc((var(--bank-inner-width) - ((var(--tile-count, 7) - 1) * var(--tile-gap))) / var(--tile-count, 7))) * 0.62), 30px);
}

.letter-tile:hover,
.bank-tile:hover {
  background: var(--tile-neutral-bg-hover);
}

.tile-active {
  cursor: grab;
}

.tile-active:hover {
  transform: translateY(-1px);
  border-color: #cccccc;
}

.tile-inactive {
  background: var(--tile-neutral-bg);
  color: #222;
}

.tile-inactive:hover {
  background: var(--tile-neutral-bg);
  transform: none;
}

body.theme-dark .tile-inactive,
body.theme-dark .tile-inactive:hover {
  background: var(--tile-neutral-bg);
  color: #222;
}

.tile-inactive .tile-value {
  color: rgba(0, 0, 0, 0.72);
}

.tile-consumed,
.bank-tile.tile-typed-used {
  background: #e5e5e5;
  color: #999999;
  border-color: #d0d0d0;
  cursor: default;
  transform: none;
}

.tile-consumed:hover,
.bank-tile.tile-typed-used:hover {
  background: #e5e5e5;
  transform: none;
}

.tile-consumed .tile-value,
.bank-tile.tile-typed-used .tile-value {
  color: #777777;
}

body.theme-dark .tile-consumed,
body.theme-dark .tile-consumed:hover,
body.theme-dark .bank-tile.tile-typed-used,
body.theme-dark .bank-tile.tile-typed-used:hover {
  background: #e5e5e5;
  color: #999999;
  border-color: #d0d0d0;
}

.tile-ghost {
  opacity: 0.45;
  outline: 2px dashed var(--accent);
  outline-offset: -3px;
}

.current-row-tile {
  cursor: pointer;
  pointer-events: auto;
}

.drop-zone-active {
  border-radius: 8px;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: rgba(79, 195, 247, 0.08);
}

.tile-value {
  position: absolute;
  right: 4px;
  bottom: 3px;
  color: rgba(0, 0, 0, 0.72);
  font-size: clamp(9px, 2vw, 12px);
  font-weight: 700;
  pointer-events: none;
}

.bank-tile.selected,
.letter-tile.selected,
.tile-tap-selected {
  background: #d9d9d9;
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

span.scoreBonus1,
span.scoreBonus2,
span.scoreBonus3 {
  position: relative;
}

span.scoreBonus1::before,
span.scoreBonus2::before,
span.scoreBonus3::before {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

span.scoreBonus1::before {
  background: var(--bonus-1);
}

span.scoreBonus2::before {
  background: var(--bonus-2);
}

span.scoreBonus3::before {
  background: var(--bonus-3);
}

#submission {
  width: var(--game-width);
  margin: clamp(3px, calc(var(--row-height) * 0.08), 8px) auto 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--submission-gap);
}

#text-entry {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
}

#player-letters {
  width: 100%;
  max-width: none;
  height: calc(var(--control-size) + 2px);
  margin-left: 0;
  padding: 0 10px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: #fafafa;
  color: #222;
  text-transform: uppercase;
  font-size: clamp(20px, calc(var(--control-size) * 0.58), 24px);
  font-weight: 400;
  letter-spacing: 5px;
  transition:
    color 0.18s ease,
    opacity 0.18s ease;
}

#player-letters.undo-prompt {
  color: #777;
  font-weight: 600;
  letter-spacing: 1px;
}

#player-letters.undo-prompt-fading {
  color: transparent;
}

.click-to-submit,
.click-to-exchange,
.click-to-shuffle,
.click-to-undo {
  width: var(--control-size);
  height: var(--control-size);
  flex: 0 0 var(--control-size);
  margin: 0;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: #fff;
  color: #111;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 26px;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    opacity 0.16s ease,
    transform 0.16s ease;
}

.click-to-submit,
.click-to-exchange {
  margin-left: 0;
}

.click-to-submit {
  background: var(--tile-bg);
}

.click-to-exchange {
  background: var(--bonus-2);
}

.click-to-shuffle {
  background: var(--bonus-1);
}

.click-to-undo {
  background: #f3b6b1;
}

.click-to-submit:hover,
.click-to-exchange:hover,
.click-to-shuffle:hover,
.click-to-undo:hover {
  border-color: #ccc;
  filter: none;
  transform: translateY(-1px);
}

.click-to-submit:hover {
  background: var(--tile-bg-hover);
}

.click-to-exchange:hover {
  background: #b9cbe2;
}

.click-to-shuffle:hover {
  background: var(--tile-bg-hover);
}

.click-to-undo:hover {
  background: #ffc7c2;
}

.click-to-exchange.used-exchange {
  opacity: 0.35;
  cursor: default;
  filter: grayscale(1);
}

#click-me.submit-disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(1);
  pointer-events: none;
}

#new-word {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.copy-link {
  margin: 0 5px;
  color: var(--tile-bg);
  text-decoration: underline;
  cursor: pointer;
}

.copy-link:hover,
.copy-link.clicked {
  color: var(--accent);
}

#overlay-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.42);
}

#overlay-backdrop.hidden {
  display: none;
}

.overlay-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(90vw, 420px);
  max-height: min(82svh, 620px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  padding: 16px 18px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text);
}

.overlay-close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

#overlay-title {
  margin: 0 24px 12px 0;
  font-size: 18px;
  font-weight: 800;
}

#overlay-body,
#overlay-body p {
  font-size: 14px;
  line-height: 1.45;
}

#overlay-body p {
  margin: 0 0 10px;
}

.theme-options {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.theme-options label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: #222;
  font-size: 14px;
  cursor: pointer;
}

.small-note {
  color: var(--muted);
  font-size: 13px !important;
}

.archive-summary {
  text-align: center;
}

#archive-calendar {
  max-width: 260px;
  margin: 8px auto 0;
}

.archive-cal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px 0;
}

.cal-month-label {
  min-width: 126px;
  text-align: center;
  font-weight: 700;
}

.cal-nav {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: #222;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.archive-cal-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 8px;
}

.cal-dow {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.cal-empty {
  min-height: 30px;
  aspect-ratio: 1 / 1;
}

.cal-cell {
  position: relative;
  z-index: 2;
  min-height: 30px;
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 10px;
  cursor: default;
  overflow: visible;
}

.cal-clickable {
  cursor: pointer;
}

.cal-clickable:hover {
  outline: 2px solid var(--accent);
}

.cal-day-number {
  position: relative;
  z-index: 2;
  font-size: 10px;
  font-weight: 800;
}

.cal-other-month {
  opacity: 0.45;
}

.cal-future {
  opacity: 0.25;
}

.cal-star-0-star {
  background: var(--slot-bg);
}

.cal-star-1-star,
.cal-star-1-circle {
  background: var(--bonus-1);
}

.cal-star-2-star,
.cal-star-2-circle {
  background: var(--bonus-2);
}

.cal-star-3-star,
.cal-star-3-circle {
  background: var(--bonus-3);
}

.cal-star-0-star::before,
.cal-star-1-star::before,
.cal-star-1-circle::before,
.cal-star-2-star::before,
.cal-star-2-circle::before,
.cal-star-3-star::before,
.cal-star-3-circle::before {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.88);
  font-size: 22px;
  line-height: 1;
}

.cal-star-0-star::before,
.cal-star-1-star::before,
.cal-star-2-star::before,
.cal-star-3-star::before {
  content: "★";
  font-size: 25px;
}

.cal-star-1-circle::before,
.cal-star-2-circle::before,
.cal-star-3-circle::before {
  content: "●";
}

.cal-streak-connector {
  position: absolute;
  top: 50%;
  z-index: -1;
  width: 32%;
  height: 5px;
  transform: translateY(-50%);
  pointer-events: none;
}

.cal-streak-connector-right {
  left: 88%;
}

.cal-streak-connector-left {
  right: 88%;
}

.cal-streak-link-0 {
  background: var(--slot-bg);
}

.cal-streak-link-1 {
  background: var(--bonus-1);
}

.cal-streak-link-2 {
  background: var(--bonus-2);
}

.cal-streak-link-3 {
  background: var(--bonus-3);
}

@keyframes progress-bar-animation {
  0% {
    opacity: 0;
    transform: translateX(-100%);
  }
  50% {
    opacity: 1;
    transform: translateX(30%);
  }
  70% {
    transform: translateX(0%);
  }
  80% {
    transform: translateX(-3%);
  }
  90% {
    transform: translateX(0%);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

@keyframes flash {
  0% {
    border-color: transparent;
  }
  40% {
    border-color: var(--danger);
  }
  100% {
    border-color: transparent;
  }
}

.flash-border {
  animation: flash 0.3s linear forwards;
}

@keyframes disappear {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(0);
  }
}

@keyframes drop-in {
  0% {
    opacity: 0;
    transform: translateY(-10px) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes win-star-pop {
  0% {
    opacity: 0;
    transform: translateY(14px) scale(0);
  }
  55% {
    opacity: 1;
    transform: translateY(-6px) scale(1.16);
  }
  78% {
    opacity: 1;
    transform: translateY(2px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes confetti-fall {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--confetti-dx, 0px), var(--confetti-distance, 400px)) rotate(720deg);
    opacity: 0;
  }
}

@keyframes meter-star-shower {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.25) rotate(0deg);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--star-dx, 0px)), calc(-50% + var(--star-dy, -60px))) scale(1.05) rotate(240deg);
  }
}

@media (min-width: 590px) {
  body {
    padding: 12px;
  }
}

@media (max-width: 430px) {
  body {
    justify-content: flex-start;
    padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
  }

  #top-bar {
    gap: 6px;
  }

  .top-hud {
    gap: 6px;
  }

  h1 {
    font-size: clamp(1.08rem, 5vw, 1.45rem);
  }

  .puzzle-row {
    min-height: var(--row-height);
  }

  #submission {
    gap: 6px;
  }

  #text-entry {
    display: none;
  }

  .click-to-submit,
  .click-to-exchange,
  .click-to-shuffle,
  .click-to-undo {
    width: var(--control-size);
    height: var(--control-size);
  }
}
