:root {
  color-scheme: light;
  --ink: #2c2118;
  --muted: #786d5f;
  --paper: #f3e5c7;
  --paper-strong: #fff4d6;
  --jade: #657f6b;
  --jade-dark: #3d5d4c;
  --cinnabar: #a53a28;
  --gold: #bd8e2f;
  --sky: #9fb5ad;
  --line: rgba(74, 49, 27, 0.2);
  --shadow: 0 22px 62px rgba(58, 39, 20, 0.28);
  --scroll-overhang: clamp(56px, 7vw, 108px);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(201, 154, 62, 0.34), transparent 25rem),
    radial-gradient(circle at 86% 18%, rgba(100, 127, 107, 0.24), transparent 28rem),
    repeating-linear-gradient(90deg, rgba(76, 49, 23, 0.035) 0 1px, transparent 1px 18px),
    linear-gradient(135deg, #e6d5ad 0%, #f6ecd3 44%, #c09345 100%);
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.24), transparent 16rem),
    repeating-linear-gradient(135deg, rgba(44, 33, 24, 0.025) 0 2px, transparent 2px 7px);
  mix-blend-mode: multiply;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1220px, calc(100vw - (var(--scroll-overhang) * 2) - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 34px;
  display: grid;
  gap: 0;
}

html.idiom-fit-window,
html.idiom-fit-window body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

html.idiom-fit-window .shell {
  min-height: 0;
  transform: scale(var(--idiom-fit-scale, 1));
  transform-origin: top center;
}

.scroll-panel {
  position: relative;
  width: calc(100% + var(--scroll-overhang) * 2);
  margin-inline: calc(var(--scroll-overhang) * -1);
  overflow: hidden;
  background-color: transparent;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border: 0;
  box-shadow: none;
}

.top-scroll {
  display: grid;
  gap: 12px;
  padding: 54px calc(18px + var(--scroll-overhang)) 18px;
  border-radius: 8px 8px 0 0;
  background-image: url("assets/graphics/realistic-scroll-top-transparent.png?v=real-scroll-5");
}

.bottom-scroll {
  display: grid;
  gap: 12px;
  padding: 18px calc(18px + var(--scroll-overhang)) 54px;
  border-radius: 0 0 8px 8px;
  background-image: url("assets/graphics/realistic-scroll-bottom-transparent.png?v=real-scroll-5");
}

.scroll-rod {
  display: none;
  position: absolute;
  left: -18px;
  right: -18px;
  z-index: 3;
  height: 34px;
  border-radius: 999px;
  pointer-events: none;
  background:
    linear-gradient(90deg, #17100a 0 3%, transparent 3% 97%, #17100a 97% 100%),
    linear-gradient(180deg, #3a2110 0%, #81551a 12%, #f3d76a 32%, #c18a23 56%, #5b3514 82%, #1b1008 100%);
  border: 1px solid rgba(33, 20, 10, 0.78);
  box-shadow:
    inset 0 4px 7px rgba(255, 243, 169, 0.56),
    inset 0 -6px 11px rgba(42, 25, 9, 0.54),
    0 7px 14px rgba(46, 28, 11, 0.3);
}

.scroll-rod::before,
.scroll-rod::after {
  position: absolute;
  top: 50%;
  width: 48px;
  height: 48px;
  content: "";
  border-radius: 50%;
  background:
    radial-gradient(circle, #5a3a17 0 18%, #15100c 20% 42%, #7b531c 44% 58%, #21150b 60% 100%);
  transform: translateY(-50%);
  box-shadow:
    inset 0 4px 8px rgba(255, 238, 153, 0.22),
    inset 0 -8px 12px rgba(0, 0, 0, 0.52);
}

.scroll-rod::before {
  left: -18px;
}

.scroll-rod::after {
  right: -18px;
}

.scroll-rod-top {
  top: -16px;
}

.scroll-rod-bottom {
  bottom: -16px;
}

.topbar,
.idiom-card,
.lesson,
.controls {
  position: relative;
  z-index: 1;
  background:
    linear-gradient(180deg, rgba(255, 246, 218, 0.84), rgba(236, 216, 176, 0.78)),
    repeating-linear-gradient(90deg, transparent 0 18px, rgba(92, 62, 29, 0.04) 19px);
  border: 1px solid rgba(104, 70, 28, 0.3);
  box-shadow:
    inset 0 0 0 1px rgba(255, 253, 236, 0.46),
    0 8px 18px rgba(58, 39, 20, 0.08);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 18px;
  border-radius: 8px;
}

.kicker {
  margin: 0 0 3px;
  color: var(--cinnabar);
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  line-height: 1.05;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, #c79a3e, #9e6e23);
  color: #fff5d7;
  font-size: 1.35rem;
  font-weight: 900;
  box-shadow: 0 8px 20px rgba(88, 56, 18, 0.24);
  touch-action: manipulation;
  user-select: none;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.icon-button:not(:disabled):active {
  transform: translateY(1px);
}

.stats span,
.lesson div {
  min-width: 92px;
  padding: 8px 12px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 248, 225, 0.9), rgba(241, 225, 190, 0.88));
  border: 1px solid var(--line);
}

.stats strong,
.lesson strong {
  color: var(--jade-dark);
}

.idiom-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.82fr) minmax(280px, 1.3fr);
  align-items: stretch;
  gap: 14px;
  padding: 14px;
  border-radius: 8px;
}

.hint {
  padding: 12px 14px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(165, 58, 40, 0.1), rgba(189, 142, 47, 0.18)),
    repeating-linear-gradient(135deg, transparent 0 12px, rgba(72, 47, 25, 0.035) 13px);
  display: grid;
  gap: 4px;
}

.hint span,
.lesson span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.hint strong {
  font-size: clamp(1rem, 2.3vw, 1.45rem);
  line-height: 1.28;
}

.idiom-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.slot {
  min-height: 72px;
  border-radius: 8px;
  border: 2px solid rgba(116, 79, 36, 0.28);
  background:
    linear-gradient(180deg, rgba(255, 246, 218, 0.9), rgba(235, 215, 174, 0.92)),
    repeating-linear-gradient(90deg, transparent 0 19px, rgba(116, 79, 36, 0.06) 20px);
  display: grid;
  place-items: center;
  font-size: clamp(1.8rem, 6vw, 3.15rem);
  font-weight: 900;
  color: rgba(34, 48, 45, 0.32);
  transition: transform 180ms ease, color 180ms ease, border-color 180ms ease;
}

.slot.filled {
  color: var(--cinnabar);
  border-color: rgba(217, 79, 43, 0.52);
  transform: translateY(-2px);
}

.game-wrap {
  position: relative;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#game {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(70, 45, 20, 0.36);
  box-shadow:
    inset 0 0 0 2px rgba(255, 247, 215, 0.55),
    0 18px 42px rgba(58, 39, 20, 0.22);
  background: #eadcbf;
}

.overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(44, 33, 24, 0.34);
}

.overlay.is-visible {
  display: grid;
}

#startPanel {
  background:
    linear-gradient(90deg, rgba(44, 33, 24, 0.64), rgba(44, 33, 24, 0.1) 48%, rgba(44, 33, 24, 0.52)),
    linear-gradient(180deg, rgba(44, 33, 24, 0.08), rgba(44, 33, 24, 0.54)),
    url("assets/graphics/idiom-dash-agentopia-painting-playfield.png?v=real-scroll-5") center / cover no-repeat;
  place-items: center start;
}

.panel {
  width: min(480px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 245, 218, 0.97), rgba(236, 216, 176, 0.97)),
    repeating-linear-gradient(135deg, transparent 0 18px, rgba(165, 58, 40, 0.055) 19px);
  border: 1px solid rgba(118, 82, 36, 0.42);
  box-shadow: var(--shadow);
  text-align: center;
}

#startPanel .panel {
  margin-left: clamp(0px, 4vw, 38px);
  text-align: left;
}

#startPanel .seal {
  margin-left: 0;
}

.panel h2 {
  margin-top: 7px;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.08;
}

.panel p {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.62;
}

.panel.meaning h2 {
  color: var(--cinnabar);
}

.seal {
  width: fit-content;
  margin: 0 auto;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--cinnabar);
  color: #fffaf0 !important;
  font-weight: 900;
}

.primary,
.controls button {
  min-height: 46px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, #b9432d, #8f2f20);
  color: #fff3cf;
  font-weight: 850;
  border: 1px solid rgba(89, 45, 20, 0.28);
  box-shadow: 0 8px 20px rgba(92, 45, 20, 0.24);
}

.primary {
  margin-top: 22px;
  min-width: 156px;
  padding: 0 20px;
}

.primary:active,
.controls button:active {
  transform: translateY(1px);
}

.controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
}

.controls button {
  padding: 0 12px;
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
}

.controls button.is-active {
  background:
    linear-gradient(180deg, #d4a23d, #a77625);
  color: #2c2118;
}

.lesson {
  display: grid;
  grid-template-columns: minmax(130px, 0.48fr) minmax(130px, 0.48fr) minmax(260px, 1fr);
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
}

.lesson div {
  display: grid;
  gap: 4px;
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 18px, 620px);
    padding-top: 10px;
    gap: 0;
  }

  .scroll-panel {
    width: 100%;
    margin-inline: 0;
  }

  .top-scroll {
    padding-right: 14px;
    padding-left: 14px;
  }

  .bottom-scroll {
    padding-right: 14px;
    padding-left: 14px;
  }

  .topbar,
  .idiom-card,
  .lesson {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    align-items: stretch;
  }

  .stats {
    width: 100%;
    justify-content: stretch;
  }

  .stats span {
    flex: 1;
  }

  .slot {
    min-height: 58px;
  }

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

  #jumpButton,
  #pauseButton {
    grid-column: span 1;
  }
}

@media (max-width: 430px) {
  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls button {
    min-height: 44px;
    padding: 0 8px;
  }

  #pauseButton {
    grid-column: span 2;
  }
}
