:root {
  color-scheme: dark;
  --ink: #f8f5ee;
  --ink-muted: #c7c3d9;
  --night-950: #080718;
  --night-900: #100d2d;
  --night-800: #191442;
  --night-700: #25205c;
  --paper: #fffaf0;
  --paper-2: #f4ead7;
  --paper-ink: #27223d;
  --paper-muted: #746c83;
  --gold: #ffc94d;
  --gold-bright: #ffe58d;
  --gold-deep: #b97716;
  --cyan: #61d9ec;
  --cyan-deep: #197f94;
  --saffron: #ec8e24;
  --emerald: #2fbf8f;
  --rose: #db5d70;
  --focus: #8de8f5;
  --radius-xl: 32px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --shadow-strong: 0 28px 80px rgba(3, 2, 14, 0.48);
  --font-size-base: 1rem;
  --text-meta: 0.875rem;
  --text-label: 0.875rem;
  --text-secondary: 1rem;
  --text-copy: 1rem;
  --text-emphasis: 1.25rem;
  --inverse-font-scale: 1;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--night-950);
  font-size: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(67, 57, 145, 0.28), transparent 32rem),
    radial-gradient(circle at 82% 32%, rgba(27, 126, 150, 0.16), transparent 30rem),
    var(--night-950);
  font-family: "Sarabun", "Noto Sans Thai", Tahoma, sans-serif;
  font-size: var(--font-size-base);
  line-height: 1.55;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: 10px;
  color: #111;
  background: var(--gold-bright);
  font-weight: 800;
}

.skip-link:focus {
  transform: translateY(0);
}

.app {
  min-height: 100vh;
}

.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 40;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: max(10px, env(safe-area-inset-top)) clamp(14px, 3vw, 38px) 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(10, 8, 31, 0.76);
  box-shadow: 0 12px 36px rgba(4, 3, 18, 0.16);
  backdrop-filter: blur(20px) saturate(130%);
}

.back-to-games {
  display: grid;
  width: 42px;
  height: 42px;
  flex: none;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  text-decoration: none;
}

.back-to-games svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-to-games:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
  background: rgba(255, 201, 77, 0.14);
}

.brand {
  display: inline-flex;
  min-width: 0;
  min-height: 48px;
  flex: 0 1 auto;
  align-items: center;
  gap: 11px;
  margin-right: auto;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.brand > span:last-child {
  min-width: 0;
}

.brand__bolt {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 229, 141, 0.65);
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255, 201, 77, 0.08);
  box-shadow: 0 0 24px rgba(255, 201, 77, 0.2);
}

.brand__bolt img {
  width: 100%;
  height: 100%;
  display: block;
}

.brand strong,
.brand small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand strong {
  letter-spacing: 0.01em;
  font-size: 1.125rem;
  line-height: 1.25;
  white-space: nowrap;
}

.brand small {
  margin-top: 1px;
  color: #a8a3c5;
  letter-spacing: 0.025em;
  font-size: var(--text-meta);
  font-weight: 500;
  line-height: 1.2;
  opacity: 0.72;
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
}

.session-status {
  color: var(--ink-muted);
  font-size: var(--text-label);
  font-weight: 700;
}

.icon-button {
  display: inline-flex;
  min-width: 48px;
  min-height: 48px;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.icon-button__large {
  color: var(--gold-bright);
  font-size: 1.25em;
  font-weight: 800;
}

.settings-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  color: #f6f3fa;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 800;
  white-space: nowrap;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.settings-button:hover {
  border-color: rgba(255, 229, 141, 0.5);
  background: rgba(255, 255, 255, 0.13);
  transform: translateY(-1px);
}

.settings-button svg,
.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.view {
  min-height: 100vh;
  padding-top: 72px;
}

.home-view {
  position: relative;
  display: grid;
  min-height: 100svh;
  align-items: center;
  overflow: hidden;
}

.home-art,
.home-scrim,
.victory-art,
.victory-scrim {
  position: absolute;
  inset: 0;
}

.home-art,
.victory-art {
  background-image: url("/assets/game/sondhi-thunder-loom/key-art.jpg?v=20260815.17");
  background-position: center center;
  background-size: cover;
  transform: scale(1.015);
}

.home-scrim {
  background:
    linear-gradient(90deg, rgba(8, 7, 24, 0.96) 0%, rgba(8, 7, 24, 0.75) 40%, rgba(8, 7, 24, 0.16) 75%),
    linear-gradient(0deg, rgba(8, 7, 24, 0.82) 0%, transparent 45%);
}

.home-content {
  position: relative;
  z-index: 2;
  width: min(1040px, calc(100% - clamp(16px, 7vw, 110px) - 32px));
  margin: 0 auto 0 clamp(16px, 7vw, 110px);
  padding: clamp(20px, 3.5vh, 48px) 0 44px;
}

.eyebrow {
  margin: 0 0 13px;
  color: var(--gold-bright);
  letter-spacing: 0.06em;
  font-size: var(--text-label);
  font-weight: 800;
  text-transform: uppercase;
}

.home-content h1,
.victory-content h1 {
  margin: 0;
  color: #fff;
  letter-spacing: 0;
  font-size: clamp(2rem, calc(1.2rem + 2.2vw), 2.9rem);
  line-height: 1.2;
  text-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

.home-title {
  display: grid;
  gap: 0.11em;
}

.home-title__line {
  display: block;
  padding-block: 0.04em;
  line-height: 1.22;
}

.home-title__line--accent {
  color: var(--gold-bright);
}

/* วรรคปิดประโยคต้องไม่ถูกตัดกลาง ไม่งั้นได้ "นั่น / คือ สนธิ" ห้อยคนละบรรทัด */
.home-lead__punch {
  white-space: nowrap;
}

/* บรรทัดขยาย — เล็กและจางกว่าประโยคเปิด ให้ลำดับการอ่านชัด */
.home-lead--sub {
  margin-top: 10px;
  color: #c2bcd6;
  font-size: clamp(0.95rem, 1.6vw, 1.1rem);
}

/* คำว่า "สนธิ" คือคีย์เวิร์ดของทั้งเกม ให้เด่นออกจากประโยครอบข้าง */
.home-lead b {
  color: var(--gold-bright);
  font-weight: 800;
}

.home-lead {
  max-width: 650px;
  margin: 14px 0 0;
  color: #e6e2ee;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  line-height: 1.75;
  text-wrap: pretty;
}

.reflex-grid {
  display: grid;
  max-width: 650px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.reflex-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  background: rgba(18, 14, 54, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
}

.reflex-card__number {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #2d2109;
  background: linear-gradient(145deg, var(--gold-bright), var(--gold));
  box-shadow: 0 7px 22px rgba(255, 201, 77, 0.22);
  font-weight: 900;
}

.reflex-card strong {
  display: block;
  color: #fff;
  font-size: var(--text-emphasis);
}

.reflex-card p {
  margin: 3px 0 0;
  color: var(--ink-muted);
  font-size: var(--text-secondary);
  line-height: 1.45;
}

.home-actions {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 26px;
}

.home-actions p {
  margin: 0;
  color: #b9b4cc;
  font-size: var(--text-label);
}

.source-ribbon {
  position: absolute;
  right: clamp(16px, 4vw, 54px);
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: rgba(255, 255, 255, 0.74);
  font-size: var(--text-meta);
}

.source-ribbon__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 12px rgba(47, 191, 143, 0.7);
}

.mode-console {
  max-width: 940px;
  margin-top: 30px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 26px;
  background: rgba(10, 8, 34, 0.78);
  box-shadow: 0 24px 70px rgba(2, 2, 12, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(22px) saturate(125%);
}

.mode-console__heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.section-kicker {
  margin: 0 0 3px;
  color: var(--cyan);
  letter-spacing: 0.05em;
  font-size: var(--text-meta);
  font-weight: 900;
  text-transform: uppercase;
}

.mode-console h2,
.settings-panel h2 {
  margin: 0;
  color: #fff;
  font-size: clamp(1.4rem, 3vw, 2rem);
  line-height: 1.35;
  text-wrap: balance;
}

.corpus-badge {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  padding: 7px 12px;
  border: 1px solid rgba(97, 217, 236, 0.34);
  border-radius: 999px;
  color: #d9fbff;
  background: rgba(97, 217, 236, 0.1);
  font-size: var(--text-label);
  font-weight: 800;
  white-space: nowrap;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px;
  margin-top: 18px;
}

.mode-card {
  position: relative;
  display: grid;
  min-height: 118px;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 13px;
  align-items: start;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 18px;
  color: #f4f1fa;
  background: rgba(255, 255, 255, 0.055);
  cursor: pointer;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.mode-card:hover {
  border-color: rgba(255, 229, 141, 0.55);
  transform: translateY(-2px);
}

.mode-card.is-selected {
  border-color: rgba(255, 229, 141, 0.55);
}

.mode-card:active:not(:disabled) {
  transform: translateY(1px) scale(0.995);
}

.mode-card:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.mode-card__icon {
  display: grid;
  min-width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 13px;
  color: #2b210a;
  background: linear-gradient(145deg, var(--gold-bright), var(--gold));
  font-size: var(--text-copy);
  font-weight: 900;
}

.mode-card__icon svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.mode-card strong,
.mode-card small,
.mode-card em {
  display: block;
}

.mode-card strong {
  font-size: var(--text-emphasis);
}

.mode-card small {
  margin-top: 3px;
  color: #c8c3d8;
  font-size: var(--text-copy);
  font-style: normal;
  line-height: 1.55;
}

.mode-card em {
  grid-column: 2;
  color: var(--gold-bright);
  font-size: var(--text-meta);
  font-style: normal;
  font-weight: 800;
}

.mode-card em span {
  display: inline-block;
  transition: transform 160ms ease;
}

.mode-card:hover em span {
  transform: translateX(3px);
}

.session-options {
  margin-top: 18px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 16px;
  background: rgba(3, 2, 18, 0.28);
}

.session-options > summary {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 15px;
  color: #f4f1fa;
  cursor: pointer;
  line-height: 1.5;
}

.session-options > summary strong {
  font-size: var(--text-copy);
}

.session-options > summary span {
  color: #bdb8cc;
  font-size: var(--text-meta);
  text-align: right;
}

.session-options[open] > summary {
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.session-builder {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 13px;
  margin-top: 0;
  padding: 16px;
}

.session-builder fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

#poolFieldset {
  grid-column: span 2;
}

.session-builder legend {
  margin-bottom: 7px;
  color: #d8d3e4;
  font-size: var(--text-label);
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(3, 2, 18, 0.45);
}

.segmented.segmented--pool {
  grid-auto-flow: row;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.segmented button {
  min-height: 44px;
  padding: 7px 9px;
  border: 0;
  border-radius: 10px;
  color: #beb9cf;
  background: transparent;
  cursor: pointer;
  font-size: var(--text-label);
  font-weight: 800;
}

.segmented button.is-selected {
  color: #2c220b;
  background: var(--gold-bright);
  box-shadow: 0 4px 13px rgba(255, 201, 77, 0.18);
}

.session-builder select {
  width: 100%;
  min-height: 54px;
  padding: 9px 38px 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  color: #f7f4fb;
  background: #171337;
  cursor: pointer;
  font-size: var(--text-copy);
  font-weight: 700;
}

.session-builder fieldset:disabled select,
.session-builder fieldset:disabled button {
  cursor: not-allowed;
}

.session-builder__note {
  margin: 0;
  padding: 0 16px 16px;
  color: #cbc6d8;
  font-size: var(--text-copy);
  line-height: 1.65;
  text-wrap: pretty;
}

.home-notice {
  margin: 14px 0 0;
  padding: 12px 14px;
  border: 1px solid rgba(255, 229, 141, 0.38);
  border-radius: 14px;
  color: #fff4c7;
  background: rgba(121, 83, 17, 0.25);
  font-size: var(--text-copy);
  line-height: 1.6;
}

.mastery-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-top: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.12);
}

.corpus-summary {
  margin: 13px 2px 0;
  color: #bbb6ca;
  font-size: var(--text-meta);
  line-height: 1.6;
  text-wrap: pretty;
}

.mastery-strip div {
  display: flex;
  min-height: 72px;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  background: rgba(10, 8, 34, 0.92);
}

.mastery-strip strong {
  color: var(--cyan);
  font-size: 1.55rem;
}

.mastery-strip span {
  color: #c8c3d8;
  font-size: var(--text-label);
  line-height: 1.5;
}

.memory-console {
  margin-top: 18px;
  padding: clamp(16px, 2.6vw, 24px);
  border: 1px solid rgba(97, 217, 236, 0.28);
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(23, 19, 58, 0.96), rgba(10, 37, 50, 0.9));
}

.memory-console__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.memory-console h3 {
  color: #fff;
  font-size: 1.35rem;
  line-height: 1.35;
}

.memory-console__heading p,
.memory-console__note {
  margin: 5px 0 0;
  max-width: 62ch;
  color: #cbc6d8;
  font-size: var(--text-copy);
  line-height: 1.65;
  text-wrap: pretty;
}

.button--memory {
  flex: 0 0 auto;
  border: 1px solid rgba(97, 217, 236, 0.58);
  color: #e9fcff;
  background: #153e4c;
}

.button--secondary {
  border: 1px solid rgba(97, 217, 236, 0.5);
  color: #e9fcff;
  background: #153e4c;
}

.memory-counts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.memory-counts div {
  min-height: 84px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(4, 5, 25, 0.38);
}

.memory-counts strong,
.memory-counts span {
  display: block;
}

.memory-counts strong {
  color: var(--cyan);
  font-size: 1.55rem;
  line-height: 1.25;
}

.memory-counts span {
  margin-top: 3px;
  color: #d6d1df;
  font-size: var(--text-label);
  line-height: 1.5;
}

.memory-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 15px;
}

.method-atlas {
  margin-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.13);
}

.method-atlas summary {
  min-height: 52px;
  padding: 15px 2px 8px;
  color: var(--gold-bright);
  cursor: pointer;
  font-size: var(--text-emphasis);
  font-weight: 800;
  line-height: 1.6;
}

.method-atlas > p {
  max-width: 70ch;
  margin: 4px 0 14px;
  color: #d1ccdd;
  font-size: var(--text-copy);
  line-height: 1.7;
  text-wrap: pretty;
}

.method-atlas__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.method-atlas__item {
  min-height: 96px;
  padding: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.055);
}

.method-atlas__item strong,
.method-atlas__item span,
.method-atlas__item small {
  display: block;
}

.method-atlas__item strong {
  color: #fff;
  font-size: var(--text-emphasis);
}

.method-atlas__item span {
  margin-top: 2px;
  color: #d5d0df;
  font-size: var(--text-copy);
  line-height: 1.55;
}

.method-atlas__item small {
  margin-top: 7px;
  color: var(--cyan);
  font-size: var(--text-meta);
  font-weight: 800;
}

.button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 19px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}

.button:hover:not(:disabled) {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.button--primary {
  color: #2d2109;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold) 58%, #e9a52a);
  box-shadow: 0 12px 28px rgba(255, 188, 50, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.button--large {
  min-height: 56px;
  padding: 14px 25px;
  border-radius: 17px;
  font-size: 1.03rem;
}

.button--ghost {
  border: 1px solid #d4c9b4;
  color: #5c526f;
  background: rgba(255, 255, 255, 0.58);
}

.button--ghost-light {
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.button--full {
  width: 100%;
}

.play-view {
  padding-bottom: 56px;
  background:
    radial-gradient(circle at 15% 18%, rgba(77, 65, 160, 0.25), transparent 30rem),
    linear-gradient(180deg, #100d2d, #080718);
}

.play-shell {
  display: grid;
  width: min(1440px, calc(100% - 40px));
  grid-template-columns: minmax(0, 1.08fr) minmax(420px, 0.92fr);
  gap: clamp(18px, 3vw, 36px);
  align-items: start;
  margin: 0 auto;
  padding-top: clamp(28px, 5vh, 58px);
}

.world-panel {
  position: sticky;
  top: 98px;
  min-height: min(72vh, 760px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-strong);
  isolation: isolate;
}

.world-panel img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 44% center;
}

.world-panel__shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(6, 4, 18, 0.46), transparent 38%, rgba(6, 4, 18, 0.12) 56%, rgba(6, 4, 18, 0.88) 100%),
    linear-gradient(90deg, transparent 55%, rgba(7, 5, 20, 0.18));
}

.world-panel__top {
  position: absolute;
  top: 22px;
  right: 22px;
  left: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.region-pill,
.exam-pill,
.mode-pill,
.direction-badge,
.pair-state {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: var(--text-label);
  font-weight: 800;
}

.region-pill {
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  background: rgba(10, 8, 31, 0.6);
  backdrop-filter: blur(12px);
}

.exam-pill {
  color: #36250a;
  background: rgba(255, 229, 141, 0.92);
}

.mode-pill {
  border: 1px solid rgba(97, 217, 236, 0.4);
  color: #d9fbff;
  background: rgba(13, 42, 57, 0.76);
}

/* ตั้งแต่ 721px ขึ้นไป แถบบนบอก "สายฟ้าแลบ · ข้อ ๑/๑๐" อยู่แล้ว ป้ายนี้จึงเป็นข้อมูลซ้ำ
   (ต่ำกว่านั้นแถบบนซ่อนสถานะ ป้ายนี้เลยยังต้องอยู่) */
@media (min-width: 721px) {
  .mode-pill {
    display: none;
  }
}

.tapestry-progress {
  position: absolute;
  right: 24px;
  bottom: 92px;
  left: 24px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 18px;
  background: rgba(9, 7, 28, 0.68);
  backdrop-filter: blur(16px);
}

.tapestry-progress__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #d9d4e6;
  font-size: var(--text-label);
}

.tapestry-progress__label strong {
  color: var(--gold-bright);
}

.loom-path {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--round-count, 10), minmax(22px, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.loom-path::before {
  position: absolute;
  top: 50%;
  right: 3%;
  left: 3%;
  height: 2px;
  background: rgba(255, 255, 255, 0.18);
  content: "";
  transform: translateY(-50%);
}

.loom-path__node {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(32px, 100%);
  height: 32px;
  place-self: center;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  color: #bdb8cd;
  background: #242045;
  font-size: var(--text-meta);
  font-weight: 800;
}

.loom-path__node.is-active {
  border-color: var(--cyan);
  color: #08151a;
  background: var(--cyan);
  box-shadow: 0 0 0 5px rgba(97, 217, 236, 0.13), 0 0 24px rgba(97, 217, 236, 0.4);
}

.loom-path__node.is-complete {
  border-color: var(--gold-bright);
  color: #2d2109;
  background: var(--gold-bright);
}

.novice-line {
  position: absolute;
  right: 24px;
  bottom: 24px;
  left: 24px;
  margin: 0;
  padding: 6px 10px;
  border-radius: 12px;
  color: #eeeaf4;
  background: rgba(9, 7, 28, 0.72);
  font-size: var(--text-copy);
  line-height: 1.6;
  text-align: center;
  text-wrap: pretty;
}

.challenge-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: var(--radius-xl);
  color: var(--paper-ink);
  background:
    radial-gradient(circle at 80% 0, rgba(255, 201, 77, 0.16), transparent 18rem),
    linear-gradient(150deg, #fffdf7, #f5ead7);
  box-shadow: var(--shadow-strong);
}

.challenge-card::before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 5px;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--saffron));
  content: "";
}

.challenge-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 24px 26px 0;
}

.direction-badge {
  color: #153e48;
  background: #dff7fa;
}

.pair-state {
  color: #7b5a1e;
  background: rgba(255, 201, 77, 0.18);
}

.challenge-intro {
  padding: 28px 26px 20px;
  text-align: center;
}

.challenge-kicker {
  margin: 0;
  color: #6c617c;
  font-size: var(--text-copy);
  font-weight: 800;
}

.challenge-intro h2 {
  overflow-wrap: anywhere;
  margin: 12px 0 7px;
  color: #1e183a;
  letter-spacing: 0;
  font-size: clamp(2.4rem, 5vw, 4.8rem);
  line-height: 1.22;
}

.challenge-note {
  margin: 0;
  color: var(--paper-muted);
  font-size: var(--text-secondary);
  line-height: 1.65;
  text-wrap: balance;
}

#answerForm {
  padding: 0 26px 25px;
}

.choice-answer {
  padding: 0 26px 25px;
}

.choice-answer__instruction {
  margin: 0 0 12px;
  color: #6b6277;
  font-size: var(--text-copy);
  line-height: 1.65;
  text-align: center;
  text-wrap: pretty;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.choice-button {
  position: relative;
  display: grid;
  min-height: 78px;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border: 2px solid #d8cdb9;
  border-radius: 16px;
  color: #2e2741;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-weight: 800;
  line-height: 1.55;
  text-align: left;
}

.choice-button:hover:not(:disabled) {
  border-color: var(--cyan-deep);
  background: #fff;
}

.choice-button__key {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  color: #5b5269;
  background: #eee7da;
}

.choice-button.is-correct {
  border-color: #2ba77f;
  color: #115b46;
  background: #e2f8ef;
}

.choice-button.is-wrong {
  border-color: #cf687b;
  color: #843144;
  background: #fde9ed;
}

.choice-button:disabled {
  cursor: default;
  opacity: 0.78;
}

.choice-button.is-correct:disabled,
.choice-button.is-wrong:disabled {
  opacity: 1;
}

.join-answer label,
.field-group label {
  display: block;
  margin-bottom: 7px;
  color: #635b70;
  font-size: var(--text-label);
  font-weight: 800;
}

.join-answer input,
.field-group input {
  width: 100%;
  min-height: 65px;
  border: 2px solid #d7cbb6;
  border-radius: 16px;
  color: #211b39;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 2px 4px rgba(62, 46, 20, 0.04);
  font-size: clamp(1.42rem, 3vw, 2rem);
  font-weight: 800;
  text-align: center;
}

.join-answer input:focus,
.field-group input:focus {
  border-color: var(--cyan-deep);
  background: #fff;
}

.split-answer {
  display: flex;
  gap: 12px;
  align-items: end;
}

.plus {
  display: grid;
  width: 40px;
  min-height: 65px;
  place-items: center;
  color: #9c7a31;
  font-size: 1.45rem;
  font-weight: 900;
}

.field-group {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
}

.field-group.is-locked input {
  border-color: #6acaaa;
  color: #145d48;
  background: #e8fbf4;
}

.field-group.is-locked::after {
  position: absolute;
  top: 42px;
  right: 12px;
  color: #198263;
  content: "✓";
  font-weight: 900;
}

.field-group.is-wrong input {
  border-color: #d88997;
  background: #fff5f6;
}

.answer-actions {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 10px;
  margin-top: 16px;
}

.feedback {
  min-height: 0;
  margin: 0 26px;
  padding: 0;
  border-radius: 13px;
  color: #5b5267;
  font-size: var(--text-copy);
  font-weight: 700;
  line-height: 1.6;
  text-align: center;
}

.feedback:not(:empty) {
  min-height: 48px;
  padding: 12px 14px;
}

.feedback--wrong {
  color: #8a3042;
  background: #fde9ed;
}

.feedback--partial {
  color: #79591b;
  background: #fff2ce;
}

.feedback--correct {
  color: #12654d;
  background: #e4f8f0;
}

.feedback--hint {
  color: #4d4a8b;
  background: #ecebff;
}

.junction-hint {
  margin: 14px 26px 0;
  padding: 15px;
  border: 1px dashed #c49d4a;
  border-radius: 15px;
  background: rgba(255, 246, 216, 0.72);
  text-align: center;
}

.junction-hint__label {
  margin: 0 0 7px;
  color: #725821;
  font-size: var(--text-label);
  font-weight: 800;
}

.junction-hint__word {
  color: #30283e;
  font-size: 1.42rem;
  font-weight: 900;
}

.answer-reveal {
  margin-top: 25px;
  padding: 25px 26px 28px;
  border-top: 1px solid #dbcfbc;
  background: rgba(255, 255, 255, 0.45);
}

.answer-reveal__success {
  display: flex;
  align-items: center;
  gap: 12px;
}

.success-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--emerald);
  box-shadow: 0 8px 22px rgba(47, 191, 143, 0.24);
  font-weight: 900;
}

.answer-reveal__success p,
.answer-reveal__success h3 {
  margin: 0;
}

.answer-reveal__success p {
  color: #4f7367;
  font-size: var(--text-label);
  font-weight: 800;
}

.answer-reveal__success h3 {
  color: #201a36;
  font-size: var(--text-emphasis);
}

.equation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  margin: 20px 0;
  padding: 17px 12px;
  border: 1px solid #dbcba9;
  border-radius: 17px;
  color: #211a38;
  background: linear-gradient(145deg, #fffaf0, #f7e9ca);
  font-size: clamp(1.28rem, 2.7vw, 1.85rem);
  font-weight: 900;
}

.equation--compact {
  margin: 8px 0 0;
  padding: 10px;
  font-size: 1.15rem;
}

.equation__source {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.equation__operator,
.equation__arrow {
  color: #9f7b2c;
}

.word-segment.is-changed {
  position: relative;
  color: #9b580c;
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-decoration-thickness: 4px;
  text-underline-offset: 6px;
}

.explanation {
  margin-bottom: 17px;
  border: 1px solid #d9ccb8;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.62);
}

.explanation summary {
  min-height: 48px;
  padding: 13px 15px;
  color: #4c435c;
  cursor: pointer;
  font-size: var(--text-emphasis);
  font-weight: 800;
  line-height: 1.6;
}

.explanation__plain {
  margin: 0;
  padding: 0 15px 14px;
  color: #5f566d;
  font-size: var(--text-copy);
  line-height: 1.75;
  text-wrap: pretty;
}

.technical-note {
  margin: 0 12px 12px;
  padding: 12px;
  border-radius: 12px;
  color: #5f566d;
  background: #eee7da;
}

.technical-note span,
.technical-note strong {
  display: block;
}

.technical-note span {
  color: #8c7b67;
  font-size: var(--text-meta);
  font-weight: 800;
  line-height: 1.5;
  text-transform: uppercase;
}

.technical-note strong {
  margin-top: 4px;
  color: #3b334b;
  font-size: var(--text-emphasis);
  line-height: 1.6;
}

.technical-note p {
  margin: 6px 0 0;
  font-size: var(--text-copy);
  line-height: 1.65;
  text-wrap: pretty;
}

.exam-history {
  margin: 0 12px 12px;
  padding: 12px;
  border: 1px solid #dec27e;
  border-radius: 12px;
  color: #604713;
  background: #fff5d8;
  font-size: var(--text-copy);
  line-height: 1.65;
}

.settings-dialog,
.memory-dialog {
  width: min(620px, calc(100% - 24px));
  max-height: calc(100svh - 24px);
  overflow: auto;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 26px;
  color: var(--paper-ink);
  background: var(--paper);
  box-shadow: 0 36px 100px rgba(0, 0, 0, 0.62);
}

/* กล่องตั้งค่าอยู่ในธีมกลางคืนของเกม ไม่ใช่กระดาษสว่างที่กระโดดออกจากฉาก */
.settings-dialog {
  width: min(500px, calc(100% - 24px));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-lg);
  color: var(--ink);
  background: linear-gradient(180deg, #141033 0%, #0d0a24 100%);
  box-shadow: 0 30px 90px rgba(2, 1, 12, 0.66);
}

.memory-dialog {
  width: min(940px, calc(100% - 24px));
}

.settings-dialog::backdrop,
.memory-dialog::backdrop {
  background: rgba(5, 4, 18, 0.78);
  backdrop-filter: blur(8px);
}

.memory-panel {
  padding: clamp(18px, 4vw, 30px);
}

.memory-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.memory-panel h2 {
  color: #241d3a;
  font-size: clamp(1.5rem, 4vw, 2rem);
  line-height: 1.35;
}

.memory-panel__header p {
  margin: 5px 0 0;
  color: #6a6278;
  font-size: var(--text-copy);
  line-height: 1.6;
}

.memory-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 20px;
}

.memory-dialog .button--secondary {
  border-color: #b9ab8f;
  color: #393146;
  background: #f5ecdc;
}

.memory-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 20px;
  padding-bottom: 12px;
}

.memory-filters button {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 13px;
  border: 1px solid #d8cdbb;
  border-radius: 12px;
  color: #5d5569;
  background: #fff;
  cursor: pointer;
  font-size: var(--text-label);
  font-weight: 800;
}

.memory-filters button.is-selected {
  border-color: #226f80;
  color: #fff;
  background: #226f80;
}

.memory-list {
  display: grid;
  gap: 9px;
  max-height: min(56vh, 620px);
  overflow: auto;
  padding: 2px 4px 4px 0;
}

.memory-empty {
  padding: 26px 16px;
  border: 1px dashed #cfc3b1;
  border-radius: 14px;
  color: #655c70;
  background: #fff;
  font-size: var(--text-copy);
  line-height: 1.65;
  text-align: center;
}

.memory-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 15px;
  border: 1px solid #ded4c3;
  border-left: 5px solid #a89e8c;
  border-radius: 14px;
  color: #302941;
  background: #fff;
}

.memory-row--due { border-left-color: #c36b2d; }
.memory-row--learning { border-left-color: #b69332; }
.memory-row--strong { border-left-color: #25846c; }
.memory-row--new { border-left-color: #8b8298; }

.memory-row__equation {
  color: #27213b;
  font-size: var(--text-emphasis);
  font-weight: 900;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.memory-row__meta {
  margin-top: 4px;
  color: #6b6277;
  font-size: var(--text-label);
  line-height: 1.55;
}

.memory-row__state {
  min-width: 150px;
  text-align: right;
}

.memory-row__state strong,
.memory-row__state span {
  display: block;
}

.memory-row__state strong {
  color: #51465f;
  font-size: var(--text-copy);
}

.memory-row__state span {
  margin-top: 3px;
  color: #72697c;
  font-size: var(--text-label);
  line-height: 1.5;
}

.settings-panel {
  padding: clamp(18px, 4vw, 26px);
}

.settings-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
}

.settings-panel__eyebrow {
  display: block;
  color: var(--gold);
  letter-spacing: 0.16em;
  font-size: var(--text-label);
  font-weight: 800;
}

.settings-panel h2 {
  margin-top: 2px;
  color: var(--ink);
}

.settings-close {
  display: grid;
  width: 40px;
  height: 40px;
  flex: none;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.settings-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.settings-close:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
}

.setting-row,
.setting-toggle {
  display: flex;
  width: 100%;
  min-height: 68px;
  align-items: center;
  gap: 14px;
  margin: 0;
  padding: 14px 4px;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.setting-toggle {
  cursor: pointer;
}

.setting-toggle:hover {
  background: rgba(255, 255, 255, 0.04);
}

.setting-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: none;
  place-items: center;
  border-radius: 12px;
  color: var(--gold);
  background: rgba(255, 201, 77, 0.12);
}

.setting-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.setting-row > div,
.setting-copy {
  flex: 1 1 auto;
  min-width: 0;
}

.setting-row strong,
.setting-toggle strong,
.setting-toggle small {
  display: block;
}

.setting-row strong,
.setting-toggle strong {
  color: var(--ink);
  font-size: var(--text-copy);
}

.setting-row p,
.setting-toggle small {
  margin: 2px 0 0;
  color: var(--ink-muted);
  font-size: var(--text-label);
  line-height: 1.55;
  text-wrap: pretty;
}

/* สวิตช์จริง — เห็นสถานะได้จากรูปทรง ไม่ต้องอ่านคำว่าเปิด/ปิด */
.setting-switch {
  position: relative;
  width: 52px;
  height: 30px;
  flex: none;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  transition: background 0.18s ease, border-color 0.18s ease;
}

.setting-switch i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #cfd3e6;
  transition: transform 0.18s ease, background 0.18s ease;
}

.setting-toggle[aria-pressed="true"] .setting-switch {
  border-color: rgba(47, 191, 143, 0.8);
  background: rgba(47, 191, 143, 0.32);
}

.setting-toggle[aria-pressed="true"] .setting-switch i {
  background: var(--emerald);
  transform: translateX(22px);
}

.setting-toggle:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
  border-radius: 12px;
}

.font-stepper {
  display: grid;
  flex: none;
  grid-template-columns: 40px 62px 40px;
  align-items: center;
}

.font-stepper button {
  min-width: 40px;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 11px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 900;
}

.font-stepper button:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
}

.font-stepper output {
  color: var(--ink);
  font-size: var(--text-copy);
  font-weight: 900;
  text-align: center;
}

body.is-reduced *,
body.is-reduced *::before,
body.is-reduced *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  scroll-behavior: auto !important;
  transition-duration: 0.01ms !important;
}

.challenge-card.is-success::before {
  background: linear-gradient(90deg, var(--emerald), var(--gold), var(--emerald));
}

.challenge-card.is-success .answer-reveal {
  animation: reveal-rise 420ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.challenge-card.is-error {
  animation: soft-nudge 300ms ease;
}

.victory-view {
  position: relative;
  display: grid;
  min-height: 100svh;
  place-items: center;
  overflow: hidden;
}

.victory-art {
  background-position: center;
}

.victory-scrim {
  background:
    radial-gradient(circle at center, rgba(14, 10, 39, 0.42), rgba(8, 7, 24, 0.9) 72%),
    linear-gradient(180deg, transparent, rgba(8, 7, 24, 0.75));
}

.victory-content {
  position: relative;
  z-index: 2;
  width: min(760px, calc(100% - 32px));
  padding: 50px 0;
  text-align: center;
}

.victory-seal {
  display: grid;
  width: 80px;
  height: 80px;
  place-items: center;
  margin: 0 auto 22px;
  border: 2px solid var(--gold-bright);
  border-radius: 50%;
  color: #2d2109;
  background: radial-gradient(circle, var(--gold-bright), var(--gold));
  box-shadow: 0 0 0 9px rgba(255, 201, 77, 0.12), 0 0 55px rgba(255, 201, 77, 0.34);
  font-size: 2rem;
  font-weight: 900;
}

.victory-seal svg {
  width: 42px;
  height: 42px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.victory-content h1 {
  font-size: clamp(2.8rem, 7vw, 5.8rem);
}

.victory-content > p:not(.eyebrow) {
  max-width: 650px;
  margin: 22px auto 0;
  color: #dfdbea;
  font-size: 1.03rem;
}

.victory-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 29px;
}

.victory-stats article {
  padding: 18px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  background: rgba(14, 11, 42, 0.64);
  backdrop-filter: blur(14px);
}

.victory-stats strong,
.victory-stats span {
  display: block;
}

.victory-stats strong {
  color: var(--gold-bright);
  font-size: 1.8rem;
}

.victory-stats span {
  color: #bfb9cf;
  font-size: var(--text-label);
}

.victory-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 11px;
  margin-top: 26px;
}

@keyframes reveal-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes soft-nudge {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-5px); }
  70% { transform: translateX(4px); }
}

@media (max-width: 1040px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }

  .mode-card {
    min-height: 92px;
  }

  .method-atlas__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .play-shell {
    width: min(760px, calc(100% - 28px));
    grid-template-columns: 1fr;
  }

  /* จอแคบวางเป็นแนวตั้ง ถ้าปล่อยให้การ์ดภาพสูงเท่าเดิม โจทย์จะตกใต้ขอบจอทุกข้อ
     จึงยุบเป็น "แถบสถานะ" สูงเท่าที่จำเป็น — ภาพถอยไปเป็นพื้นหลัง เหลือของที่ต้องดูจริง
     คือ เขต · ป้ายเคยออกสอบ · ลูกคิดบอกว่าอยู่ข้อไหน */
  .world-panel {
    position: relative;
    top: auto;
    display: grid;
    min-height: 0;
    gap: 10px;
    padding: 12px 14px;
  }

  .world-panel img {
    object-position: center 38%;
    opacity: 0.55;
  }

  .world-panel__shade {
    background: linear-gradient(180deg, rgba(6, 4, 18, 0.72), rgba(6, 4, 18, 0.82));
  }

  .world-panel__top,
  .tapestry-progress {
    position: static;
    right: auto;
    bottom: auto;
    left: auto;
  }

  .world-panel__top {
    z-index: 1;
  }

  .tapestry-progress {
    z-index: 1;
    padding: 0;
    border: 0;
    background: none;
    backdrop-filter: none;
  }

  .tapestry-progress .loom-path {
    margin-top: 8px;
  }

  /* คำคมเป็นบรรยากาศ ไม่ใช่ข้อมูลที่ต้องใช้ตอบ — จอแคบสละที่ให้โจทย์ */
  .novice-line {
    display: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    min-height: 64px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .brand small,
  .session-status {
    display: none;
  }

  .topbar__actions {
    gap: 7px;
  }

  .brand {
    gap: 8px;
  }

  .brand strong {
    font-size: 1rem;
  }

  .brand__bolt {
    width: 38px;
    height: 38px;
  }

  .view {
    padding-top: 64px;
  }

  .home-view {
    align-items: end;
  }

  .home-art {
    background-position: 58% center;
  }

  .home-scrim {
    background:
      linear-gradient(0deg, rgba(8, 7, 24, 0.98) 0%, rgba(8, 7, 24, 0.88) 46%, rgba(8, 7, 24, 0.15) 83%),
      linear-gradient(90deg, rgba(8, 7, 24, 0.28), transparent);
  }

  .home-content {
    width: calc(100% - 28px);
    margin: 0 auto;
    padding: 11vh 0 40px;
  }

  .mode-console {
    padding: 16px;
  }

  .mode-console__heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .session-builder {
    grid-template-columns: 1fr;
  }

  #poolFieldset {
    grid-column: auto;
  }

  .segmented.segmented--pool {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mastery-strip {
    grid-template-columns: 1fr;
  }

  .mastery-strip div {
    min-height: 58px;
  }

  .memory-console__heading {
    align-items: stretch;
    flex-direction: column;
  }

  .button--memory {
    width: 100%;
  }

  .memory-counts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .memory-actions,
  .memory-dialog__actions {
    flex-direction: column;
  }

  .memory-actions .button,
  .memory-dialog__actions .button {
    width: 100%;
  }

  .memory-row {
    grid-template-columns: 1fr;
  }

  .memory-row__state {
    min-width: 0;
    text-align: left;
  }

  .method-atlas__grid {
    grid-template-columns: 1fr;
  }

  .home-content h1 {
    font-size: clamp(1.85rem, calc(1rem + 4.4vw), 2.5rem);
  }

  .home-title__line {
    white-space: nowrap;
  }

  .home-lead {
    margin-top: 18px;
    font-size: 1rem;
  }

  .reflex-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
  }

  /* จอแคบ: บีบการ์ดสองใบเป็นแถบเตี้ยแถวเดียว เหลือแต่หัวข้อ
     คำอธิบายซ้ำกับคำโปรยข้างบนอยู่แล้ว และพอบีบเป็นคอลัมน์แคบจะตัดเป็นสามบรรทัดอ่านยาก */
  .reflex-card {
    min-height: 0;
    gap: 9px;
    padding: 9px 11px;
  }

  .reflex-card p {
    display: none;
  }

  .reflex-card strong {
    font-size: 0.95rem;
  }

  .reflex-card__number {
    width: 30px;
    height: 30px;
    font-size: 0.875rem;   /* ห้ามต่ำกว่านี้ — เกณฑ์อ่านออก ๑๔px ของทั้งเกม */
  }

  .home-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .home-actions .button {
    width: 100%;
  }

  .source-ribbon {
    right: 14px;
    left: 14px;
    justify-content: center;
    text-align: center;
  }

  .play-view {
    padding-bottom: 28px;
  }

  .play-shell {
    width: calc(100% - 20px);
    gap: 12px;
    padding-top: 12px;
  }

  .world-panel {
    padding: 10px 12px;
    border-radius: 24px;
  }

  .world-panel__top {
    top: 14px;
    right: 14px;
    left: 14px;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .exam-pill {
    margin-left: auto;
  }

  .tapestry-progress {
    padding: 0;
  }

  .loom-path__node {
    width: 30px;
    height: 30px;
  }

  .novice-line {
    right: 13px;
    bottom: 16px;
    left: 13px;
  }

  .challenge-card {
    border-radius: 24px;
  }

  .challenge-card__header {
    padding: 20px 18px 0;
  }

  .challenge-intro {
    padding: 22px 18px 16px;
  }

  .challenge-intro h2 {
    font-size: clamp(2.15rem, 11vw, 3.2rem);
  }

  #answerForm,
  .choice-answer,
  .answer-reveal {
    padding-right: 18px;
    padding-left: 18px;
  }

  .feedback,
  .junction-hint {
    margin-right: 18px;
    margin-left: 18px;
  }

  .split-answer {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .choice-grid {
    grid-template-columns: 1fr;
  }

  .setting-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .plus {
    width: 100%;
    min-height: 28px;
  }

  .answer-actions {
    grid-template-columns: 1fr;
  }

  .answer-actions .button--primary {
    grid-row: 1;
  }

  .equation {
    align-items: stretch;
    flex-direction: column;
  }

  .equation__arrow {
    transform: rotate(90deg);
  }

  .victory-stats {
    grid-template-columns: 1fr;
  }

  .victory-stats article {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 16px;
  }

  .victory-stats strong {
    font-size: 1.45rem;
  }

  .victory-actions {
    flex-direction: column;
  }
}

@media (max-width: 380px) {
  .brand__bolt {
    display: none;
  }

  .icon-button {
    min-width: 44px;
    min-height: 44px;
  }

  .world-panel {
    padding: 9px 10px;
  }

  .region-pill,
  .exam-pill {
    padding: 4px 8px;
    font-size: var(--text-meta);
  }

  .loom-path {
    gap: 3px;
  }

  .loom-path__node {
    width: 28px;
    height: 28px;
    font-size: var(--text-meta);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .home-art,
  .victory-art {
    transform: none;
  }
}
