@font-face {
  font-family: "Sebang Gothic";
  src: url("/fonts/SebangGothic-Regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Mind Safari Emoji";
  src: url("/fonts/NotoEmoji-MindSafari.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Sebang Gothic";
  src: url("/fonts/SebangGothic-Bold.woff2") format("woff2");
  font-style: normal;
  font-weight: 700 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --sky: #bfe8f7;
  --sky-deep: #8ed2eb;
  --surface: #f9fdff;
  --surface-soft: #eaf7fc;
  --ink: #14243d;
  --ink-soft: #52647a;
  --line: #8ebbd0;
  --line-strong: #254b67;
  --accent: #db4f7d;
  --accent-dark: #a82455;
  --mint: #d9f4e6;
  --mint-ink: #185f42;
  --warning: #ffc928;
  --danger: #b91c36;
  --focus: #0b4fa3;
  --font-page-title: clamp(20px, 2.1vw, 25px);
  --font-section-title: 17px;
  --font-body: 14px;
  --font-control: 14px;
  --font-label: 13px;
  --font-help: 12px;
  --font-meta: 10px;
  --radius: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --z-dialog: 50;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--sky);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgb(255 255 255 / 56%) 0 7rem, transparent 7.1rem),
    linear-gradient(155deg, #d6f2fc 0%, var(--sky) 44%, #a9dded 100%);
  font-family: "Sebang Gothic", "Malgun Gothic", sans-serif;
  font-size: var(--font-body);
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
.cell:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

svg {
  display: block;
}

.icon-sprite {
  position: fixed;
  inline-size: 0;
  block-size: 0;
  pointer-events: none;
}

.skip-link {
  position: fixed;
  inset: 6px auto auto 6px;
  z-index: 100;
  padding: 10px 14px;
  color: #fff;
  background: var(--ink);
  border-radius: 10px;
  transform: translateY(-140%);
  transition: transform 160ms var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(100%, 1060px);
  margin-inline: auto;
  padding:
    max(6px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

.topbar,
.brand-block,
.utility-actions,
.mission-heading,
.piece-count,
.theme-button,
.dialog-header {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}

.brand-block {
  min-width: 0;
  gap: var(--space-2);
}

.brand-block img {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.brand-block h1,
.brand-block p,
.mission-heading h2,
.message,
.app-footer,
.notice-date,
.app-dialog p {
  margin: 0;
}

.brand-block h1 {
  font-size: var(--font-page-title);
  line-height: 1.05;
  letter-spacing: -.02em;
}

.brand-block p {
  margin-top: 1px;
  color: #365a70;
  font-size: var(--font-help);
}

.utility-actions {
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: var(--space-1);
}

.network-chip {
  font-size: var(--font-meta);
  font-weight: 700;
  letter-spacing: .01em;
}

.network-chip {
  min-height: 26px;
  padding: 5px 8px;
  color: var(--mint-ink);
  background: var(--mint);
  border-radius: 999px;
  white-space: nowrap;
}

.network-chip.offline {
  color: #7d2c00;
  background: #ffe7c2;
}

.icon-button,
.dialog-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  transition: background-color 180ms var(--ease), color 180ms var(--ease), transform 120ms var(--ease);
}

.icon-button {
  gap: 5px;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: var(--font-label);
  font-weight: 700;
}

.icon-button svg,
.dialog-close svg,
.mode-tab > svg,
.action-button svg,
.theme-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.icon-button:hover,
.dialog-close:hover {
  background: #fff;
}

.icon-button:active,
.dialog-close:active,
.action-button:active,
.theme-button:active,
.mode-tab:active {
  transform: scale(.97);
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  margin-top: 6px;
}

.mode-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 52px;
  gap: var(--space-2);
  padding: 6px 10px;
  color: var(--ink);
  background: rgb(249 253 255 / 84%);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  text-align: left;
  transition: background-color 200ms var(--ease), color 200ms var(--ease), transform 120ms var(--ease);
}

.mode-tab > svg {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
}

.mode-tab span {
  min-width: 0;
}

.mode-tab b,
.mode-tab small {
  display: block;
}

.mode-tab b {
  font-size: var(--font-control);
}

.mode-tab small {
  color: var(--ink-soft);
  font-size: var(--font-meta);
  font-weight: 400;
}

.mode-tab[aria-selected="true"] {
  color: #fff;
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.mode-tab[aria-selected="true"] small {
  color: #ffe8ef;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin-top: 6px;
  overflow: clip;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.score-strip > div {
  min-width: 0;
  padding: 5px 8px;
  background: rgb(249 253 255 / 92%);
  text-align: center;
}

.score-strip span,
.piece-count small,
.theme-button small {
  display: block;
  color: var(--ink-soft);
  font-size: var(--font-meta);
}

.score-strip strong {
  display: block;
  margin-top: 1px;
  font-size: var(--font-label);
  font-variant-numeric: tabular-nums;
}

.game-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "mission"
    "board"
    "actions";
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.frame {
  min-width: 0;
  background: rgb(249 253 255 / 94%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.mission-panel {
  grid-area: mission;
  padding: 8px;
}

.mission-heading {
  justify-content: space-between;
  gap: var(--space-2);
}

.mission-heading > div:first-child {
  min-width: 0;
}

.mission-heading h2 {
  font-size: var(--font-section-title);
  line-height: 1.25;
  letter-spacing: -.02em;
  text-wrap: balance;
}

.hearts {
  display: flex;
  flex: 0 0 auto;
  gap: 3px;
  color: var(--accent-dark);
}

.heart {
  width: 18px;
  height: 18px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.6;
}

.heart.empty {
  color: #8aa1af;
  fill: transparent;
}

.progress-track {
  height: 5px;
  margin-top: 5px;
  overflow: hidden;
  background: #d5e7ef;
  border-radius: 999px;
}

.progress-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent-dark);
  border-radius: inherit;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 280ms var(--ease);
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  margin-top: 6px;
}

.rule-item {
  min-width: 0;
  padding: 6px 5px;
  color: #193f58;
  background: var(--surface-soft);
  border-radius: 10px;
  font-size: var(--font-help);
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  word-break: keep-all;
}

.rule-item b {
  display: block;
  color: var(--accent-dark);
  font-size: var(--font-meta);
}

.mission-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.piece-count,
.theme-button {
  min-width: 0;
  min-height: 44px;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 11px;
}

.piece-count {
  background: #fff4d8;
}

.piece-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-family: "Mind Safari Emoji", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
}

.piece-count b,
.theme-button b {
  display: block;
  margin-top: -1px;
  font-size: var(--font-control);
  font-variant-numeric: tabular-nums;
}

.theme-button {
  width: 100%;
  color: var(--ink);
  background: var(--mint);
  border: 0;
  text-align: left;
  transition: background-color 180ms var(--ease), transform 120ms var(--ease);
}

.theme-button:hover {
  background: #c6ecd9;
}

.board-panel {
  grid-area: board;
  padding: 7px;
}

.board {
  --n: 8;
  --piece-size: 26px;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: 3px;
  width: 100%;
  max-width: 650px;
  aspect-ratio: 1;
  margin-inline: auto;
  touch-action: manipulation;
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  place-items: center;
  padding: 0;
  border: 1.5px solid #19324f;
  border-radius: 8px;
  transition: filter 140ms var(--ease), transform 100ms var(--ease), box-shadow 180ms var(--ease);
}

.cell:hover:not(:disabled) {
  filter: brightness(1.06) saturate(1.04);
}

.cell:active:not(:disabled) {
  transform: scale(.94);
}

.cell .piece {
  position: relative;
  z-index: 2;
  display: grid;
  width: clamp(24px, calc(var(--piece-size) * 1.15), 40px);
  height: clamp(24px, calc(var(--piece-size) * 1.15), 40px);
  place-items: center;
  color: var(--ink);
  background: rgb(255 255 255 / 92%);
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  font-family: "Mind Safari Emoji", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: clamp(17px, calc(var(--piece-size) * .68), 25px);
  font-weight: 400;
  line-height: 1;
}

.cell.selected {
  border-color: #fff;
  box-shadow: inset 0 0 0 3px var(--ink), inset 0 0 0 5px #fff;
}

.cell.hint {
  z-index: 2;
  box-shadow: inset 0 0 0 4px #fff, 0 0 0 4px var(--warning);
  animation: hintPulse 700ms var(--ease) infinite alternate;
}

.cell.wrong {
  animation: shake 230ms ease-in-out;
  filter: grayscale(.8) brightness(.68);
}

.cell.correct {
  box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 6px #087246;
}

.cell.mark::after,
.cell.tried::after {
  position: absolute;
  z-index: 3;
  content: "×";
  font-family: sans-serif;
  font-weight: 900;
  line-height: 1;
}

.cell.mark::after {
  color: rgb(15 35 56 / 74%);
  font-size: calc(var(--piece-size) * .72);
  text-shadow: 0 0 2px #fff;
}

.cell.tried {
  filter: grayscale(.75) brightness(.72);
}

.cell.tried::after {
  color: #fff;
  font-size: calc(var(--piece-size) * .72);
}

.cell.mark .piece,
.cell.tried .piece {
  opacity: .35;
}

@keyframes hintPulse {
  to { filter: brightness(1.1); }
}

@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.action-panel {
  grid-area: actions;
  padding: 8px;
}

.primary-controls,
.step-controls {
  display: grid;
  gap: 6px;
}

.primary-controls {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.primary-controls.find-mode {
  grid-template-columns: minmax(0, 1fr);
}

.step-controls {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 6px;
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 46px;
  gap: 6px;
  padding: 7px 9px;
  border: 0;
  border-radius: 12px;
  font-size: var(--font-control);
  font-weight: 700;
  text-align: center;
  transition: background-color 180ms var(--ease), color 180ms var(--ease), opacity 180ms var(--ease), transform 120ms var(--ease);
}

.action-button small {
  display: block;
  font-size: var(--font-meta);
  font-weight: 400;
}

.primary-controls .action-button > span,
.step-controls .action-button > span {
  white-space: nowrap;
}

.action-button.secondary {
  color: #17374e;
  background: #e5f3f9;
}

.action-button.secondary:hover:not(:disabled) {
  background: #d1eaf5;
}

.action-button.primary,
.action-button.next {
  color: #fff;
  background: var(--accent-dark);
}

.action-button.primary:hover:not(:disabled),
.action-button.next:hover:not(:disabled) {
  background: #8e1946;
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: .44;
}

.action-button.full {
  width: 100%;
  margin-top: var(--space-3);
}

.message {
  min-height: 48px;
  margin-top: 6px;
  padding: 7px 9px;
  color: #264861;
  background: #fff;
  border-radius: 10px;
  font-size: var(--font-help);
  line-height: 1.45;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 10px;
  padding: 6px 2px 0;
  color: #365a70;
  font-size: var(--font-meta);
}

.app-dialog {
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 18px;
  color: var(--ink);
  background: var(--surface);
  border: 0;
  border-radius: 16px;
  box-shadow: 0 18px 54px rgb(11 42 61 / 28%);
}

.app-dialog::backdrop {
  background: rgb(13 37 54 / 58%);
}

.app-dialog[open] {
  animation: dialogIn 200ms var(--ease);
}

@keyframes dialogIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
}

.result-dialog {
  text-align: center;
}

.dialog-visual {
  display: grid;
  width: fit-content;
  min-width: 68px;
  height: 42px;
  margin: 0 auto 8px;
  padding-inline: 12px;
  place-items: center;
  color: #fff;
  background: var(--accent-dark);
  border-radius: 10px;
  font-size: var(--font-control);
  font-weight: 700;
}

.app-dialog h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.app-dialog p,
.notice-list {
  color: var(--ink-soft);
  font-size: var(--font-control);
}

.result-dialog p {
  margin-top: 6px;
}

.dialog-header {
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.dialog-close {
  flex: 0 0 auto;
  width: 44px;
  padding: 0;
  border-radius: 12px;
}

.notice-date {
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: var(--font-help);
}

.notice-list {
  margin: 10px 0 0;
  padding-left: 20px;
}

.notice-list li + li {
  margin-top: 5px;
}

[hidden] {
  display: none !important;
}

@media (min-width: 901px) {
  .game-workspace {
    grid-template-columns: minmax(420px, 1fr) minmax(300px, 360px);
    grid-template-rows: max-content max-content minmax(0, 1fr);
    grid-template-areas:
      "board mission"
      "board actions"
      "board .";
    align-items: start;
  }

  .board-panel {
    align-self: stretch;
  }

  .mission-panel,
  .action-panel {
    align-self: start;
  }
}

@media (max-width: 620px) {
  :root {
    --font-page-title: clamp(20px, 5.8vw, 22px);
  }

  .brand-block p,
  .icon-button span,
  .network-chip {
    display: none;
  }

  .utility-actions {
    gap: 6px;
  }

  .mode-tab small {
    display: none;
  }

  .rule-item {
    font-size: 11px;
  }

  .primary-controls {
    gap: 4px;
  }

  .primary-controls .action-button {
    padding-inline: 5px;
    font-size: var(--font-label);
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: max(8px, env(safe-area-inset-left));
  }

  .brand-block img {
    width: 40px;
    height: 40px;
  }

  .board-panel {
    margin-inline: -4px;
    padding: 3px;
    border-radius: 10px;
  }

  .board {
    gap: 1px;
  }

  .cell {
    border-radius: 6px;
  }

  .rule-grid,
  .mission-stats {
    gap: 4px;
  }

  .mission-panel,
  .action-panel {
    padding: 6px;
  }

  .message {
    min-height: 44px;
  }
}

@media (max-width: 350px) {
  .mode-tab {
    padding-inline: 6px;
  }

  .mode-tab > svg {
    display: none;
  }

  .rule-item {
    padding-inline: 2px;
    font-size: 10px;
  }

  .action-button svg {
    display: none;
  }
}

@media (min-width: 560px) and (max-height: 500px) and (orientation: landscape) {
  .app-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 4px 8px;
    padding-top: max(4px, env(safe-area-inset-top));
  }

  .topbar,
  .game-workspace,
  .app-footer {
    grid-column: 1 / -1;
  }

  .mode-switch,
  .score-strip,
  .game-workspace {
    margin-top: 0;
  }

  .brand-block img {
    width: 36px;
    height: 36px;
  }

  .brand-block p,
  .app-footer {
    display: none;
  }

  .mode-tab {
    min-height: 44px;
  }

  .score-strip > div {
    padding-block: 4px;
  }

  .game-workspace {
    grid-template-columns: minmax(260px, .95fr) minmax(280px, 1.05fr);
    grid-template-rows: max-content max-content minmax(0, 1fr);
    grid-template-areas:
      "board mission"
      "board actions"
      "board .";
    align-items: start;
    gap: 6px;
  }

  .board-panel {
    padding: 4px;
  }

  .mission-panel,
  .action-panel {
    padding: 5px;
  }

  .mission-heading h2 {
    font-size: 15px;
  }

  .message {
    min-height: 36px;
    padding-block: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
