:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6f6f6f;
  --soft: #f5f5f5;
  --line: #d9d9d9;
  --dark: #050505;
  --good: #111111;
  --radius: 8px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.08);
  font-family:
    Pretendard,
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
}

.ad-banner {
  width: min(300px, calc(100% - 32px));
  aspect-ratio: 6 / 5;
  margin: 0 auto max(18px, env(safe-area-inset-bottom));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
}

.ad-banner[hidden] {
  display: none;
}

.ad-banner a,
.ad-banner img {
  display: block;
  width: 100%;
  height: 100%;
}

.ad-banner img {
  object-fit: contain;
}

button {
  font: inherit;
}

.shell {
  width: min(100%, 460px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding-top: 2px;
}

.top-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  min-height: 38px;
  flex: 0 0 auto;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.discord-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.icon-button:focus-visible,
.share-button:focus-visible,
.primary-button:focus-visible,
.found-summary button:focus-visible,
.new-game-banner button:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.share-button {
  display: grid;
  place-items: center;
  min-width: 70px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.share-button:active,
.icon-button:active {
  background: var(--soft);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  display: flex;
  align-items: center;
  min-height: 38px;
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.timer-group {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
}

.timer-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  text-align: right;
}

.timer {
  display: grid;
  place-items: center;
  min-width: 116px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
}

.timer strong {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 17px;
  line-height: 1;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.status-grid div {
  min-width: 0;
  padding: 9px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  text-align: center;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.status-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.new-game-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: var(--fg);
  color: #fff;
  animation: rise 220ms ease;
}

.new-game-banner div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.new-game-banner strong {
  font-size: 15px;
  line-height: 1.25;
}

.new-game-banner span {
  overflow: hidden;
  color: #e8e8e8;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-game-banner button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid #fff;
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.board-wrap {
  position: relative;
  padding: 8px;
  overflow: visible;
  touch-action: none;
  overscroll-behavior: contain;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  aspect-ratio: 1;
  max-height: min(72svh, 430px);
  touch-action: none;
}

.board-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

.board-lines polyline,
.board-lines line {
  fill: none;
  stroke: var(--dark);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.9;
}

.board-lines line {
  stroke-width: 5;
  opacity: 0.35;
}

.tile {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
  font-size: clamp(23px, 7vw, 36px);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  transition:
    transform 120ms ease,
    background 120ms ease,
    color 120ms ease,
    box-shadow 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.tile.selected {
  background: var(--dark);
  color: #fff;
  transform: scale(1.03);
  box-shadow: var(--shadow);
}

.tile.last {
  transform: scale(1.08);
}

.feedback {
  min-height: 26px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.feedback.good,
.feedback.bonus {
  color: var(--fg);
}

.feedback.bad {
  color: #444;
  animation: shake 180ms ease;
}

.completion {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: var(--fg);
  color: #fff;
  animation: rise 220ms ease;
}

.completion strong {
  font-size: 17px;
}

.completion span {
  font-size: 13px;
  opacity: 0.8;
}

.found-summary button {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--fg);
  cursor: pointer;
}

.found-summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.found-summary strong {
  flex: 1;
  text-align: left;
  font-size: 18px;
  font-weight: 900;
}

.found-summary em {
  font-style: normal;
  font-size: 13px;
  font-weight: 900;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-size: 14px;
  font-weight: 800;
}

.bonus-chip {
  border-color: var(--fg);
  box-shadow: inset 0 -3px 0 var(--fg);
}

.empty-list {
  color: var(--muted);
  font-size: 13px;
}

.flying-word {
  position: absolute;
  z-index: 6;
  left: var(--burst-x, 50%);
  top: var(--burst-y, 50%);
  max-width: min(82%, 320px);
  overflow: hidden;
  transform: translate(-50%, -50%);
  padding: 8px 12px;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: #fff;
  color: var(--fg);
  font-size: clamp(23px, 7vw, 36px);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  animation: wordFly 1000ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.flying-word.bonus {
  background: var(--fg);
  color: #fff;
}

.success-ring {
  position: absolute;
  z-index: 3;
  left: var(--burst-x, 50%);
  top: var(--burst-y, 50%);
  width: 38%;
  aspect-ratio: 1;
  border: 3px solid var(--fg);
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.55);
  animation: successRing 620ms ease-out forwards;
}

.success-ring.bonus {
  border-width: 4px;
}

.success-sparks {
  position: absolute;
  z-index: 4;
  left: var(--burst-x, 50%);
  top: var(--burst-y, 50%);
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.success-sparks span {
  position: absolute;
  left: 0;
  top: 0;
  width: 9px;
  height: 9px;
  border: 2px solid var(--fg);
  border-radius: 999px;
  background: #fff;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.7);
  animation: successSpark 680ms ease-out forwards;
}

.success-sparks.bonus span {
  background: var(--fg);
}

.success-sparks span:nth-child(1) {
  --spark-x: -104px;
  --spark-y: -84px;
}

.success-sparks span:nth-child(2) {
  --spark-x: 92px;
  --spark-y: -92px;
  animation-delay: 25ms;
}

.success-sparks span:nth-child(3) {
  --spark-x: 118px;
  --spark-y: 8px;
  animation-delay: 50ms;
}

.success-sparks span:nth-child(4) {
  --spark-x: 70px;
  --spark-y: 104px;
  animation-delay: 75ms;
}

.success-sparks span:nth-child(5) {
  --spark-x: -80px;
  --spark-y: 92px;
  animation-delay: 100ms;
}

.success-sparks span:nth-child(6) {
  --spark-x: -118px;
  --spark-y: 10px;
  animation-delay: 125ms;
}

.success-pop .tile {
  animation: answerPop 430ms ease;
}

.bonus-pop .tile {
  animation: answerPop 460ms ease, softPulse 520ms ease;
}

.meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding-bottom: 4px;
}

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 12px;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: var(--fg);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.3;
  pointer-events: none;
  transform: translateX(-50%);
  animation: toast 1900ms ease forwards;
}

.loading,
.error {
  margin: auto 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.loading-shell {
  min-height: 100svh;
  justify-content: center;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.loading-content h1 {
  margin: 0;
  min-height: auto;
  font-size: 44px;
  font-weight: 950;
  line-height: 0.95;
}

.loading-message {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.4;
  animation: loadingBlink 900ms ease-in-out infinite;
}

.error h1 {
  margin-bottom: 10px;
  font-size: 22px;
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 255, 255, 0.9);
}

.found-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 255, 255, 0.9);
}

.help-modal {
  width: min(100%, 390px);
  padding: 16px;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.found-modal {
  width: min(100%, 420px);
  max-height: min(72svh, 560px);
  padding: 16px;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.found-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.found-head h2 {
  font-size: 20px;
}

.found-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.help-head h2 {
  font-size: 20px;
}

.close-help,
.close-found {
  width: 34px;
  height: 34px;
  font-size: 20px;
}

.found-modal-body {
  min-height: 70px;
  overflow: auto;
  padding: 2px 2px 4px;
}

.help-modal p {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
}

.help-list {
  margin: 14px 0 16px;
  padding-left: 19px;
  color: var(--fg);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.55;
}

.help-list li + li {
  margin-top: 6px;
}

.primary-button {
  width: 100%;
  min-height: 42px;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: var(--fg);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}

@keyframes wordFly {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.9);
  }
  14% {
    opacity: 1;
    transform: translate(-50%, -58%) scale(1.04);
  }
  70% {
    opacity: 1;
    transform: translate(-50%, -88%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -155%) scale(0.96);
  }
}

@keyframes softPulse {
  0%,
  100% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.025);
  }
}

@keyframes successRing {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.55);
  }
  24% {
    opacity: 0.48;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.25);
  }
}

@keyframes successSpark {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.7);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--spark-x)), calc(-50% + var(--spark-y))) scale(0.3);
  }
}

@keyframes answerPop {
  0%,
  100% {
    transform: scale(1);
  }
  36% {
    transform: scale(1.055);
  }
  68% {
    transform: scale(0.985);
  }
}

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

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast {
  0% {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  12%,
  82% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

@keyframes loadingBlink {
  0%,
  100% {
    opacity: 0.25;
  }

  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-message {
    animation: none;
  }
}

@media (min-width: 760px) {
  body {
    background:
      linear-gradient(90deg, #f7f7f7 0, #fff 18%, #fff 82%, #f7f7f7 100%);
  }

  .shell {
    padding-top: 24px;
    padding-bottom: 12px;
  }
}

@media (max-width: 370px) {
  .shell {
    padding-left: 12px;
    padding-right: 12px;
    gap: 10px;
  }

  .board {
    gap: 6px;
  }

  .topbar {
    gap: 10px;
  }

  .top-actions {
    gap: 6px;
  }

  .brand,
  h1 {
    min-height: 34px;
  }

  h1 {
    font-size: 22px;
  }

  .icon-button {
    width: 32px;
    height: 32px;
  }

  .discord-button svg {
    width: 18px;
    height: 18px;
  }

  .share-button {
    min-width: 54px;
    height: 32px;
    padding: 0 6px;
    font-size: 11px;
  }

  .timer {
    min-width: 92px;
    height: 32px;
    padding-left: 6px;
    padding-right: 6px;
  }

  .timer strong {
    font-size: 14px;
  }

  .new-game-banner {
    align-items: flex-start;
  }

  .new-game-banner span {
    white-space: normal;
  }
}
