@import url("https://fonts.googleapis.com/css2?family=Gaegu:wght@400;700&family=Klee+One:wght@400;600&family=Song+Myung&family=Yuji+Mai&display=swap");

:root {
  --bg: #fed65a;
  --bg-soft: #ffe6a7;
  --board: #ffe6a7;
  --ink: #2b261c;
  --line: #000;
  --hi: #f3c39a;
  --hi-soft: #ffd48a;
  --bubble: #ffffff;
  --good: #3c8a4a;
  --good-bg: #b7e4c0;
  --ok-bg: #7eb8e6;
  --bad: #c45c5c;
  --shadow: rgba(80, 60, 20, 0.08);
  --cell: clamp(28px, 7.2vmin, 64px);
  --ui: "Gaegu", "Klee One", sans-serif;
  --kanji: "Yuji Mai", "Klee One", "Yu Mincho", serif;
  --hangul-piece: "Gungsuh", "GungSeo", "궁서", "Song Myung", serif;
  --coord: #c43c1a;
  --piece: #1d5aa6;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
}

body {
  overflow: hidden;
}

button,
select {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-areas:
    "top"
    "main";
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  grid-area: top;
}

.ad-banner {
  display: block;
  width: 100%;
  line-height: 0;
  background: #ffe14a;
  text-decoration: none;
  flex-shrink: 0;
}

.ad-banner img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1360 / 768;
  object-fit: contain;
  object-position: center;
}

.ad-banner-mobile {
  display: none;
}

.hamburger {
  display: none;
}

.panel-dialog-bar,
.panel-nav {
  display: none;
}

.layout {
  grid-area: main;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 0;
  gap: 12px;
}

.brand {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.04em;
}

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

.ghost-btn,
.primary-btn,
.soft-btn,
.card,
.chapter-card {
  border: 0;
  background: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 18px;
  box-shadow: none;
}

.ghost-btn.active,
.ghost-btn:hover,
.primary-btn:hover,
.soft-btn:hover {
  background: #fff;
}

#btn-bgm[aria-pressed="false"] {
  background: #efe2b8;
  color: #7a6a48;
}

.nav-prev {
  background: #d8c9a4;
  color: #4a3b28;
}

.nav-prev:hover {
  background: #cbb890;
  color: #4a3b28;
}

.nav-next {
  background: #2f7d4a;
  color: #fff;
}

.nav-next:hover {
  background: #25663c;
  color: #fff;
}

.nav-next-lesson {
  background: #1d5aa6;
  color: #fff;
}

.nav-next-lesson:hover {
  background: #164781;
  color: #fff;
}

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) auto minmax(280px, 1.15fr);
  align-items: center;
  gap: 12px 8px;
  padding: 8px 16px 24px;
  min-height: 0;
  overflow: hidden;
}

.panel-wrap {
  min-width: 0;
  min-height: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #e8c56a transparent;
}

.panel-body {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.ad-banner-panel {
  margin-top: auto;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.character-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  width: 100%;
  min-height: 0;
  padding-bottom: 0;
  overflow: hidden;
}

.character-stage img {
  width: min(100%, 46vw, 720px);
  max-height: calc(100dvh - 72px);
  height: auto;
  object-fit: contain;
  object-position: center bottom;
  image-rendering: auto;
}

.hand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  min-height: 42px;
  width: min(100%, calc(var(--cell) * 9));
}

.hand-row.gote {
  margin-bottom: 6px;
}

.hand-row.sente {
  margin-top: 4px;
}

.hand-piece {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: 0;
  padding: 0;
  width: calc(var(--cell) * 0.72);
  height: calc(var(--cell) * 0.78);
  background-image: url("../images/char.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  font-size: calc(var(--cell) * 0.36);
  line-height: 1;
}

.hand-piece .glyph {
  font-family: var(--kanji);
}

.hand-piece.hangul .glyph {
  font-family: var(--hangul-piece);
  font-size: calc(var(--cell) * 0.42);
}

.hand-piece.gote {
  transform: rotate(180deg);
}

.hand-piece .count {
  font-size: 0.7em;
}

.hand-piece.selected {
  background: var(--hi);
  border-radius: 8px;
}

.board-shell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.coord-files,
.coord-ranks {
  font-family: var(--kanji);
  font-size: calc(var(--cell) * 0.28);
  color: var(--ink);
  line-height: 1;
}

.coord-files {
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  width: calc(var(--cell) * 9);
  margin: 0 0 4px 14px;
  text-align: center;
}

.board-mid {
  display: flex;
  align-items: flex-start;
}

.coord-ranks {
  display: grid;
  grid-template-rows: repeat(9, var(--cell));
  margin-top: 14px;
  padding-left: 6px;
  place-items: center;
}

.board-wrap {
  position: relative;
  background: var(--board);
  padding: 14px;
  border: 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  grid-template-rows: repeat(9, var(--cell));
  border: 1px solid #000;
  background: var(--board);
}

.sq {
  border: 0;
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
  background: var(--board);
  display: grid;
  place-items: center;
  position: relative;
  user-select: none;
  padding: 0;
  margin: 0;
}

.sq:nth-child(9n) {
  border-right: 0;
}

.sq:nth-child(n + 73) {
  border-bottom: 0;
}

.sq.last,
.sq.hint {
  background: var(--hi);
}

.sq.selected {
  background: var(--hi-soft);
}

.sq.check {
  background: #f5b8b0;
}

.piece {
  font-family: var(--kanji);
  font-size: calc(var(--cell) * 0.42);
  line-height: 1;
  color: var(--ink);
  pointer-events: none;
  width: 86%;
  height: 90%;
  display: grid;
  place-items: center;
  background-image: url("../images/char.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.piece.hangul {
  font-family: var(--hangul-piece);
  font-size: calc(var(--cell) * 0.42);
  font-weight: 400;
}

.piece.gote {
  transform: rotate(180deg);
}

.move-line {
  margin: 8px 0 0;
  font-size: 22px;
  text-align: center;
  letter-spacing: 0.04em;
}

.lesson-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 12px;
}

.speech {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 0 0 28px;
}

.speech.bad {
  grid-template-columns: auto 1fr;
}

.bubble {
  position: relative;
  isolation: isolate;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 22px 34px 20px 26px;
  font-size: 20px;
  line-height: 1.45;
  min-height: 72px;
}

.bubble::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-style: solid;
  border-color: transparent;
  border-width: 28px 22px 26px 38px;
  border-image-source: url("../images/chat-box.png");
  border-image-slice: 32 22 28 40 fill;
  border-image-width: 28px 22px 26px 38px;
  border-image-repeat: stretch;
  pointer-events: none;
}

.speech.bad .bubble {
  padding: 22px 26px 20px 34px;
}

.speech.bad .bubble::before {
  transform: scaleX(-1);
}

.speech.ask .bubble {
  max-width: none;
}

.coord-mark {
  color: var(--coord);
  font-weight: 700;
  font-family: var(--kanji);
}

.piece-mark {
  color: var(--piece);
  font-weight: 700;
}

.mascot {
  width: 96px;
  height: auto;
  flex: 0 0 auto;
}

.verdict {
  text-align: center;
  font-size: 22px;
  margin: 0 0 20px;
}

.verdict.good {
  color: var(--good);
}

.verdict.bad {
  color: var(--bad);
}

.lesson-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.primary-btn,
.soft-btn {
  padding: 8px 16px;
}

@keyframes guide-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.22;
  }
}

.sq.correct,
.sq.hint.correct,
.sq.last.correct {
  background: var(--ok-bg);
}

.choice-ok,
.promo-pop button.choice-ok {
  background: #2f7d4a;
  color: #fff;
}

.choice-ok:hover,
.promo-pop button.choice-ok:hover {
  background: #25663c;
  color: #fff;
}

.sq.guide-blink .piece,
.sq.guide-blink:not(:has(.piece)),
.hand-piece.guide-blink,
button.guide-blink {
  animation: guide-blink 1.8s ease-in-out infinite;
}

.progress-note {
  font-size: 18px;
  margin: 0;
}

.chapter-list,
.home-grid {
  display: grid;
  gap: 10px;
}

.home-grid {
  grid-template-columns: 1fr;
}

.card,
.chapter-card {
  border-radius: 22px;
  padding: 14px 16px;
  text-align: left;
}

.chapter-card {
  width: 100%;
  display: grid;
  gap: 6px;
}

.chapter-card .meta {
  display: flex;
  justify-content: space-between;
  font-size: 16px;
}

.bar {
  height: 8px;
  background: #f0e3a8;
  border-radius: 999px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: #f2a36a;
}

.cat-title {
  margin: 18px 0 8px;
  font-size: 22px;
}

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(70, 50, 10, 0.18);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}

.modal {
  width: min(440px, 100%);
  background: var(--bg-soft);
  border: 3px solid var(--ink);
  border-radius: 28px;
  padding: 22px;
}

.modal h2 {
  margin: 0 0 12px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  font-size: 20px;
}

.setting-row select {
  border: 0;
  border-radius: 999px;
  background: #fff;
  padding: 6px 10px;
  font-size: 18px;
}

.promo-pop {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 0;
  border-radius: 24px;
  padding: 14px 16px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
}

.ai-line {
  font-size: 16px;
  opacity: 0.8;
  text-align: center;
  margin: 4px 0 0;
}

.screen-home .character-stage,
.screen-chapters .character-stage {
  align-items: center;
}

.screen-chapters .layout,
.screen-lesson .layout,
.screen-play .layout {
  align-items: stretch;
}

.screen-chapters .board-column,
.screen-lesson .board-column,
.screen-play .board-column {
  align-self: center;
}

.screen-chapters .panel-wrap,
.screen-lesson .panel-wrap,
.screen-play .panel-wrap {
  align-self: stretch;
}

.screen-lesson .panel-body,
.screen-play .panel-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.screen-lesson .speech,
.screen-play .speech {
  margin: 0 0 16px;
}

@media (max-width: 900px) {
  html,
  body {
    height: 100%;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    overflow-x: hidden;
  }

  .app-shell {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    height: 100svh;
    overflow: hidden;
    grid-template-areas:
      "top"
      "main"
      "ad";
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .ad-banner-mobile {
    display: block;
    grid-area: ad;
    height: var(--ad-h, calc(100vw * 768 / 1360));
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .ad-banner-mobile img {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: cover;
    object-position: center center;
  }

  .ad-banner-panel {
    display: none;
  }

  .topbar {
    position: relative;
    z-index: 40;
    flex-wrap: nowrap;
    padding: 8px 10px 0;
    background: var(--bg);
  }

  .app-shell.menu-open .topbar {
    background: transparent;
    pointer-events: none;
  }

  .app-shell.menu-open .brand {
    opacity: 0;
    pointer-events: none;
  }

  .app-shell.menu-open .hamburger {
    pointer-events: auto;
  }

  .brand {
    font-size: 22px;
  }

  .topbar > .top-actions {
    display: none;
  }

  .hamburger {
    display: flex;
    width: 44px;
    height: 44px;
    margin-left: auto;
    border: 0;
    border-radius: 12px;
    background: #fff;
    padding: 11px 10px;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    z-index: 41;
  }

  .hamburger span {
    display: block;
    height: 3px;
    background: var(--ink);
    border-radius: 99px;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

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

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

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

  .ghost-btn {
    padding: 5px 10px;
    font-size: 16px;
  }

  :root {
    --wrap-pad: 4px;
    --rank-w: 16px;
    --cell: calc((100vw - 8px - var(--rank-w) - 2 * var(--wrap-pad)) / 9);
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "char"
      "board";
    grid-template-rows: minmax(40px, var(--char-h, 16vh)) minmax(0, 1fr);
    justify-items: stretch;
    align-items: stretch;
    overflow: hidden;
    gap: 0;
    padding: 4px 0 6px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .character-stage {
    grid-area: char;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    height: 100%;
    max-height: var(--char-h, 16vh);
    aspect-ratio: auto;
    padding: 0;
    align-self: stretch;
    overflow: hidden;
    align-items: stretch;
    justify-content: stretch;
  }

  .character-stage img {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: cover;
    object-position: center center;
  }

  .board-column {
    grid-area: board;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    justify-content: center;
    overflow: hidden;
  }

  .board-shell {
    width: 100%;
    max-width: 100%;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .ai-line:empty {
    display: none;
  }

  .coord-files {
    width: 100%;
    margin: 0 0 4px;
    padding: 0 var(--wrap-pad);
    box-sizing: border-box;
    grid-template-columns: repeat(9, 1fr);
  }

  .board-mid {
    display: block;
    position: relative;
    width: 100%;
    max-width: 100%;
  }

  .board-wrap {
    width: 100%;
    min-width: 0;
    padding: var(--wrap-pad);
    box-sizing: border-box;
  }

  .board {
    width: 100%;
    aspect-ratio: 1;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
  }

  .coord-ranks {
    position: absolute;
    right: 2px;
    top: var(--wrap-pad);
    width: var(--rank-w);
    min-width: var(--rank-w);
    max-width: var(--rank-w);
    height: calc(100% - var(--wrap-pad));
    margin-top: 0;
    padding-left: 0;
    font-size: 12px;
    pointer-events: none;
    z-index: 1;
    grid-template-rows: repeat(9, 1fr);
  }

  .hand-row {
    width: 100%;
    max-width: 100%;
    background: var(--board);
    box-sizing: border-box;
    padding: 4px 0;
  }

  .hand-row.gote {
    margin-bottom: 0;
  }

  .hand-row.sente {
    margin-top: 0;
  }

  .panel-wrap {
    display: none;
  }

  .panel-wrap.is-open {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 30;
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    background: var(--bg);
    padding: 16px 16px 28px;
    overflow: hidden;
    align-self: stretch;
  }

  .panel-dialog-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
    min-height: 44px;
    padding-right: 52px;
  }

  .panel-dialog-bar strong {
    font-size: 24px;
    letter-spacing: 0.04em;
  }

  .panel-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
    margin: 14px 0 16px;
  }

  .panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .speech {
    grid-template-columns: 1fr 72px;
  }

  .mascot {
    width: 72px;
    height: 92px;
  }

  .screen-lesson .lesson-nav,
  .screen-play .lesson-nav {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--bg);
    padding: 6px 0 2px;
  }
}
