:root {
  --ink: #17352f;
  --ink-soft: #48645e;
  --paper: #fffdf6;
  --paper-2: #f3f8e9;
  --teal: #167f78;
  --teal-dark: #0f5f59;
  --coral: #ef654f;
  --gold: #e6aa2f;
  --green: #4a9a5b;
  --red: #c33f3f;
  --blue: #2c79b9;
  --shadow: 0 16px 42px rgba(19, 55, 47, 0.22);
  font-family: "Mali", "Leelawadee UI", sans-serif;
  font-size: 17px;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; min-height: 100%; margin: 0; }
body { overflow: hidden; background: #153e37; }
button, input, select { font: inherit; letter-spacing: 0; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #ffd86b;
  outline-offset: 2px;
}
.hidden { display: none !important; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

#app, .screen { width: 100vw; height: 100vh; height: 100dvh; min-height: 0; }
.screen { display: none; position: relative; overflow: hidden; }
.screen.active { display: block; }

.profile-screen { background: #c9e9bc; }
.profile-backdrop {
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(19, 59, 48, 0.18), rgba(19, 59, 48, 0.34)), url("../assets/stages/stage-1-orchard.png") center/cover;
}
.profile-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 40px));
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(520px, 1.2fr);
  align-items: center;
  gap: 42px;
}
.brand-block { color: white; text-shadow: 0 3px 16px rgba(8, 45, 35, 0.7); }
.brand-kicker, .dialog-kicker {
  margin: 0 0 6px;
  color: #ffe08a;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 700;
  text-transform: uppercase;
}
.brand-block h1 {
  margin: 0;
  max-width: 650px;
  font-family: "Chakra Petch", sans-serif;
  font-size: 64px;
  line-height: 1.02;
  letter-spacing: 0;
}
.thai-title { margin: 12px 0 0; font-size: 24px; font-weight: 700; }
.creator-byline { width: fit-content; margin: 14px 0 0; padding: 7px 11px; border-left: 4px solid #ffe08a; color: #ffffff; font-size: 16px; font-weight: 700; background: rgba(13, 61, 49, 0.58); }

.profile-panel {
  max-height: calc(100dvh - 48px);
  overflow: auto;
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.94);
  box-shadow: var(--shadow);
}
.field-row { display: grid; grid-template-columns: 125px 1fr; gap: 12px; align-items: center; margin-bottom: 12px; }
.field-row label, .avatar-fieldset legend { font-weight: 700; }
.field-row input, .field-row select {
  width: 100%;
  min-height: 46px;
  border: 1px solid #acc9bf;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 8px 12px;
}
.avatar-fieldset { border: 0; padding: 8px 0 0; margin: 0 0 16px; }
.avatar-fieldset legend { margin-bottom: 8px; }
.avatar-picker, .avatar-room-grid { display: grid; gap: 10px; }
.avatar-picker { grid-template-columns: repeat(4, minmax(110px, 1fr)); }
.avatar-choice {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #e7f1dd;
  cursor: pointer;
  overflow: hidden;
}
.avatar-choice img { width: 100%; height: 100%; object-fit: contain; display: block; }
.avatar-choice.selected { border-color: var(--coral); background: #fff1cf; box-shadow: 0 0 0 3px rgba(239, 101, 79, 0.18); }
.avatar-choice.locked { filter: grayscale(1); opacity: 0.62; cursor: not-allowed; }
.avatar-choice .capacity-label, .avatar-choice .lock-label { position: absolute; left: 4px; right: 4px; border-radius: 4px; color: white; font-size: 10px; font-weight: 700; padding: 2px; }
.avatar-choice .capacity-label { top: 4px; background: rgba(15, 95, 89, 0.9); }
.avatar-choice .lock-label { bottom: 4px; background: rgba(23, 53, 47, 0.9); }

.primary-command, .secondary-command, .icon-command, .hud-icon {
  min-height: 44px;
  border-radius: 6px;
  border: 0;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}
.primary-command { width: 100%; color: white; background: var(--teal); box-shadow: 0 6px 14px rgba(15, 95, 89, 0.2); }
.primary-command:hover { background: var(--teal-dark); }
.primary-command:disabled { background: #94aaa5; cursor: not-allowed; box-shadow: none; }
.secondary-command { width: 100%; margin-top: 8px; color: var(--ink); border: 1px solid #acc9bf; background: #edf5e8; }

.world-screen { overflow: auto; background: #eef5e7; }
.world-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 86px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 12px max(20px, calc((100vw - 1320px) / 2));
  background: rgba(255, 253, 246, 0.96);
  border-bottom: 1px solid #cbdccc;
  box-shadow: 0 8px 22px rgba(23, 53, 47, 0.1);
}
.player-summary { min-width: 0; display: flex; align-items: center; gap: 10px; }
.player-summary img, .hud-player img { width: 68px; height: 68px; object-fit: contain; border-radius: 8px; background: #dff0d8; }
.player-summary div { min-width: 0; display: grid; }
.player-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-summary small { color: var(--ink-soft); }
.world-title-block { text-align: center; }
.world-title-block p { margin: 0; color: var(--coral); font-weight: 700; }
.world-title-block h2 { margin: 2px 0 0; font-size: 24px; }
.world-title-block small { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.toolbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.xp-chip, .garage-chip { min-width: 86px; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 7px; border-radius: 6px; }
.xp-chip { background: #ffe3a1; }
.garage-chip { background: #d8eee5; }
.xp-chip span, .garage-chip span { font-size: 12px; font-weight: 700; }
.xp-chip span { color: #73510f; }
.garage-chip span { color: #17695d; }
.icon-command { min-width: 72px; color: var(--ink); background: #e2efe5; }

.stage-map {
  width: min(1320px, calc(100% - 40px));
  margin: 28px auto 48px;
  display: grid;
  grid-template-columns: repeat(3, minmax(250px, 1fr));
  gap: 18px;
}
.stage-card {
  position: relative;
  min-height: 260px;
  border: 0;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  text-align: left;
  color: white;
  background-position: center;
  background-size: cover;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.stage-card::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10, 35, 28, 0.02), rgba(10, 35, 28, 0.84)); }
.stage-card-content { position: absolute; inset: auto 0 0; z-index: 1; padding: 18px; }
.stage-card-content small { display: block; color: #ffe18c; font-weight: 700; }
.stage-card-content strong { display: block; margin-top: 2px; font-size: 22px; }
.stage-card-content span { display: block; margin-top: 5px; font-size: 13px; }
.stage-card-stars { position: absolute; z-index: 2; top: 12px; right: 12px; padding: 5px 8px; border-radius: 6px; background: rgba(18, 56, 47, 0.78); color: #ffd85b; }
.stage-card.locked { filter: saturate(0.35); cursor: not-allowed; }
.stage-card.locked::after { content: "ล็อก"; position: absolute; z-index: 3; inset: 50% auto auto 50%; transform: translate(-50%, -50%); padding: 8px 16px; border-radius: 6px; background: rgba(21, 45, 40, 0.88); color: white; font-weight: 700; }

.game-screen { background: #133d35; }
.game-hud {
  position: absolute;
  z-index: 20;
  top: max(8px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(250px, auto) minmax(400px, 1.25fr);
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  color: white;
  background: rgba(17, 59, 50, 0.9);
  box-shadow: 0 8px 24px rgba(9, 32, 27, 0.25);
}
.hud-player { min-width: 0; display: flex; align-items: center; gap: 8px; }
.hud-player img { width: 62px; height: 62px; background: rgba(255,255,255,0.16); }
.hud-player div { min-width: 0; display: grid; }
.hud-player strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-player span, .hud-mission span { color: #dcebe5; font-size: 14px; }
.hud-mission { text-align: center; display: grid; }
.hud-mission small { color: #ffd86b; }
.hud-mission strong { font-size: 20px; }
.hud-stats { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.hud-stat { min-width: 76px; height: 54px; display: grid; place-content: center; text-align: center; border-radius: 6px; background: rgba(255,255,255,0.11); }
.hud-stat small { font-size: 12px; color: #dcebe5; }
.hud-stat strong { font-family: "Chakra Petch", sans-serif; font-size: 21px; }
.timer-stat strong { color: #ffe07b; }
.timer-stat.warning { animation: timerPulse 0.8s infinite alternate; background: rgba(191, 57, 49, 0.68); }
.hud-icon { width: 52px; min-height: 54px; padding: 4px; color: white; border: 1px solid rgba(255,255,255,0.18); background: rgba(255,255,255,0.1); }

.game-canvas { position: absolute; inset: 0; overflow: hidden; }
.game-canvas canvas { display: block; image-rendering: auto; }
.nearby-prompt {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  min-width: 230px;
  padding: 9px 16px;
  border-radius: 6px;
  color: white;
  text-align: center;
  background: rgba(16, 58, 50, 0.9);
  box-shadow: var(--shadow);
  font-size: 18px;
  font-weight: 700;
}
.finish-stage-button {
  position: absolute;
  z-index: 21;
  top: 94px;
  right: 18px;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  padding: 8px 16px;
  color: #523600;
  font-weight: 700;
  background: #ffd665;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.touch-controls { position: absolute; z-index: 22; inset: auto 20px 18px; display: none; justify-content: space-between; align-items: end; pointer-events: none; }
.dpad { width: 152px; height: 152px; position: relative; pointer-events: auto; }
.dpad button { position: absolute; width: 52px; height: 52px; border: 1px solid rgba(255,255,255,0.5); border-radius: 50%; color: white; background: rgba(18,61,53,0.72); }
.dpad [data-direction="up"] { left: 50px; top: 0; }
.dpad [data-direction="left"] { left: 0; top: 50px; }
.dpad [data-direction="down"] { left: 50px; top: 100px; }
.dpad [data-direction="right"] { left: 100px; top: 50px; }
.action-button { width: 86px; height: 86px; pointer-events: auto; border: 3px solid rgba(255,255,255,0.7); border-radius: 50%; color: white; background: var(--coral); font-weight: 700; box-shadow: var(--shadow); }

.game-dialog {
  width: min(720px, calc(100% - 32px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid #d7e2d3;
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(8, 35, 29, 0.36);
  overflow: auto;
}
.game-dialog::backdrop { background: rgba(8, 36, 30, 0.72); }
.dialog-body { position: relative; padding: 32px; }
.dialog-body h2 { margin: 0 0 14px; font-size: 34px; }
.dialog-kicker { color: var(--coral); font-size: 15px; }
.dialog-close { position: absolute; z-index: 2; top: 10px; right: 10px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #e4eee6; color: var(--ink); font-size: 22px; cursor: pointer; }
.stage-intro-dialog { width: min(1040px, calc(100% - 32px)); }
.stage-intro-body { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 24px; align-items: center; }
.stage-intro-body > img { width: 100%; aspect-ratio: 16/10; border-radius: 8px; object-fit: cover; }
.stage-intro-body p { color: var(--ink-soft); line-height: 1.65; font-size: 18px; }
.intro-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 16px 0; }
.intro-facts span { padding: 11px; border-radius: 6px; background: #eaf3e6; text-align: center; font-size: 14px; }
.intro-facts strong { display: block; margin-top: 3px; font-size: 20px; }

.math-dialog { width: min(660px, calc(100% - 28px)); }
.math-dialog .dialog-body { text-align: center; }
.math-equation { min-height: 118px; display: flex; align-items: center; justify-content: center; gap: 16px; margin: 12px 0 16px; padding: 18px; border-radius: 8px; background: #eaf4e4; font-family: "Chakra Petch", sans-serif; font-size: 40px; font-weight: 700; }
.fraction-stack { min-width: 58px; display: inline-grid; grid-template-rows: 1fr 3px 1fr; place-items: center; vertical-align: middle; line-height: 1.05; }
.fraction-stack .bar { width: 100%; height: 3px; background: currentColor; }
.answer-display { min-height: 132px; display: flex; align-items: center; justify-content: center; gap: 14px; }
.mixed-gap { font-size: 22px; color: var(--ink-soft); }
.fraction-answer { width: 146px; display: grid; grid-template-rows: 60px 3px 60px; }
.fraction-bar { display: block; background: var(--ink); }
.answer-part { min-width: 140px; display: grid; place-content: center; border: 2px solid #c4d8cb; border-radius: 6px; background: white; color: var(--ink); cursor: text; }
.answer-part small { display: block; font-size: 12px; color: var(--ink-soft); }
.answer-part input { width: 100%; min-width: 0; height: 38px; padding: 0 4px; border: 0; outline: 0; color: var(--ink); background: transparent; font-family: "Chakra Petch", sans-serif; font-size: 30px; font-weight: 700; text-align: center; caret-color: var(--coral); }
.answer-part.active, .answer-part:focus-within { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(239,101,79,0.15); }
.whole-part { height: 70px; }
.math-feedback { min-height: 28px; margin: 4px 0; font-size: 18px; font-weight: 700; }
.math-feedback.correct { color: var(--green); }
.math-feedback.wrong { color: var(--red); }
.number-pad { width: min(440px, 100%); margin: 10px auto 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.number-pad button { height: 58px; border: 1px solid #c8d9ce; border-radius: 6px; color: var(--ink); background: white; font-family: "Chakra Petch", sans-serif; font-size: 25px; font-weight: 700; cursor: pointer; }
.number-pad button:active { transform: translateY(1px); background: #e6f2df; }

.warehouse-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(46px, 1fr)); gap: 7px; margin: 16px 0; }
.warehouse-slot { min-height: 56px; display: grid; place-content: center; border: 2px dashed #9bbbac; border-radius: 6px; background: #edf5e8; font-family: "Chakra Petch", sans-serif; font-weight: 700; }
.warehouse-slot.filled { border-style: solid; border-color: var(--gold); color: #5c4107; background: #ffe9a9; }
.deposit-equation { display: grid; grid-template-columns: 54px minmax(0, 1fr) 54px; align-items: center; gap: 10px; margin: 18px 0 14px; }
.deposit-equation > button { width: 54px; height: 54px; border: 0; border-radius: 50%; color: white; background: var(--teal); font-size: 26px; cursor: pointer; }
.deposit-equation > button:disabled { color: #71847e; background: #d2dfd8; cursor: not-allowed; }
.equation-strip { min-height: 82px; display: flex; align-items: center; justify-content: center; gap: 16px; padding: 10px 16px; border-radius: 7px; color: var(--ink); background: #fff0c3; font-family: "Chakra Petch", sans-serif; font-size: 30px; font-weight: 700; }
.equation-strip > strong { min-width: 42px; display: inline-flex; align-items: center; justify-content: center; }
.equation-strip .fraction-stack { min-width: 42px; font-size: 24px; }
.equation-symbol { color: var(--teal-dark); font-size: 28px; }

.compact-dialog { width: min(540px, calc(100% - 32px)); }
.centered-dialog { text-align: center; }
.result-stars { min-height: 52px; color: #e3a51d; font-size: 40px; }
.result-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 14px 0; }
.result-grid > div { min-height: 70px; display: grid; place-content: center; border-radius: 6px; background: #eaf3e6; }
.result-grid small { color: var(--ink-soft); }
.result-grid strong { font-family: "Chakra Petch", sans-serif; font-size: 22px; }
.result-grid .result-score { grid-column: 1 / -1; background: #ffe9a9; }
.result-grid .result-score strong { font-size: 32px; }
.result-actions { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; }
.result-actions .secondary-command { margin: 0; }

.collection-dialog { width: min(980px, calc(100% - 24px)); }
.collection-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.collection-card { position: relative; min-width: 0; border-radius: 8px; padding: 8px; background: #eaf3e6; text-align: center; }
.collection-card img { display: block; width: 100%; border-radius: 6px; }
.collection-card.locked img { filter: grayscale(1) brightness(0.45); }
.collection-card strong, .collection-card small { display: block; }
.collection-card small { color: var(--ink-soft); }
.avatar-dialog { width: min(920px, calc(100% - 32px)); }
.garage-balance { width: fit-content; margin: -6px 0 16px; padding: 8px 12px; border-radius: 6px; color: #17695d; background: #d8eee5; font-weight: 700; }
.garage-balance strong { margin-left: 5px; font-family: "Chakra Petch", sans-serif; font-size: 21px; }
.avatar-room-grid { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.garage-car { min-width: 0; padding: 10px; border: 2px solid transparent; border-radius: 8px; background: #edf5e8; text-align: center; }
.garage-car.selected { border-color: var(--coral); background: #fff2d0; }
.garage-car-visual { width: 100%; aspect-ratio: 1.25; display: grid; place-items: center; border-radius: 6px; background: #dbeed9; overflow: hidden; }
.garage-car-visual img { width: 92%; height: 92%; display: block; object-fit: contain; }
.garage-car > strong, .garage-car > small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.garage-car > strong { margin-top: 7px; font-size: 15px; }
.garage-car > small { min-height: 20px; color: var(--ink-soft); font-size: 11px; }
.garage-capacity { min-height: 34px; display: flex; align-items: center; justify-content: center; gap: 5px; margin: 5px 0 8px; border-radius: 5px; color: #17695d; background: #d8eee5; font-size: 12px; }
.garage-capacity b { font-family: "Chakra Petch", sans-serif; font-size: 15px; }
.garage-car .primary-command, .garage-car .secondary-command, .garage-buy { min-height: 40px; margin: 0; padding: 7px 8px; font-size: 13px; }
.garage-buy { width: 100%; border: 0; border-radius: 6px; color: #ffffff; background: var(--coral); font-weight: 700; cursor: pointer; }
.garage-buy:disabled { color: #687c76; background: #ccd7d2; cursor: not-allowed; }

.reward-overlay { position: fixed; z-index: 1000; inset: 0; display: none; place-items: center; padding: 16px; background: rgba(8,36,30,0.78); }
.reward-overlay.show { display: grid; }
.reward-panel { position: relative; width: min(620px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: 30px; border: 2px solid #f0bd4f; border-radius: 8px; background: #fffdf6; text-align: center; font-size: 18px; box-shadow: 0 28px 80px rgba(8,36,30,0.48); animation: rewardPop 0.55s cubic-bezier(.2,.9,.2,1.18); }
.reward-panel h2 { margin: 2px 0 10px; font-size: 38px; }
.reward-panel img { display: block; width: min(300px, 58vw); margin: 10px auto 14px; border-radius: 8px; box-shadow: 0 16px 30px rgba(35,52,40,0.24); }
.reward-sparkles { position: absolute; inset: 0; pointer-events: none; opacity: 0.65; background-image: radial-gradient(circle, #f2bd40 0 2px, transparent 3px), radial-gradient(circle, #55a9a0 0 2px, transparent 3px); background-size: 62px 62px, 91px 91px; animation: sparkleShift 2s linear infinite; }
.reward-panel > *:not(.reward-sparkles) { position: relative; z-index: 1; }

.toast { position: fixed; z-index: 1200; left: 50%; bottom: 22px; max-width: min(480px, calc(100% - 24px)); transform: translate(-50%, 20px); padding: 10px 16px; border-radius: 6px; color: white; background: rgba(18,61,53,0.94); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: 0.22s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: rgba(157,48,48,0.96); }
.loading-cover { position: fixed; z-index: 2000; inset: 0; display: grid; place-content: center; place-items: center; color: white; background: #123d35; transition: opacity 0.3s ease; }
.loading-cover.hidden-cover { opacity: 0; pointer-events: none; }
.loading-mark { width: 72px; height: 72px; display: grid; place-items: center; border: 3px solid #ffe08a; border-radius: 50%; color: #ffe08a; font-family: "Chakra Petch", sans-serif; font-size: 38px; font-weight: 700; animation: loadingSpin 1.2s ease-in-out infinite alternate; }

@keyframes timerPulse { to { transform: scale(1.04); } }
@keyframes rewardPop { from { opacity: 0; transform: scale(0.78); } }
@keyframes sparkleShift { to { background-position: 62px 62px, -91px 91px; } }
@keyframes loadingSpin { to { transform: rotate(8deg) scale(1.08); } }

@media (pointer: coarse), (max-width: 900px) {
  .touch-controls { display: flex; }
  .nearby-prompt { bottom: 110px; }
  .profile-screen { overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
  .profile-backdrop { position: fixed; }
  .profile-shell { height: auto; min-height: 100vh; min-height: 100dvh; grid-template-columns: 1fr; gap: 12px; align-content: center; padding: max(14px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom)); }
  .brand-block { text-align: center; }
  .creator-byline { margin-inline: auto; }
  .brand-block h1 { margin: auto; font-size: 42px; }
  .thai-title { font-size: 19px; }
  .profile-panel { width: 100%; max-width: 720px; max-height: none; margin: 0 auto; overflow: visible; }
  .world-toolbar { grid-template-columns: auto 1fr; }
  .world-title-block { display: none; }
  .stage-map { grid-template-columns: repeat(2, minmax(250px, 1fr)); }
  .game-hud { grid-template-columns: 1fr auto; }
  .hud-mission { display: none; }
  .hud-stats { overflow: hidden; }
  .hud-stat { min-width: 62px; }
  .hud-stat:nth-child(3), .hud-stat:nth-child(4) { display: none; }
}

@media (max-width: 680px) {
  .profile-shell { width: calc(100% - 20px); gap: 8px; align-content: start; }
  .brand-kicker { margin-bottom: 2px; font-size: 13px; }
  .brand-block h1 { font-size: 30px; line-height: 1; }
  .thai-title { margin-top: 5px; font-size: 17px; }
  .creator-byline { margin-top: 6px; padding: 4px 8px; font-size: 12px; }
  .profile-panel { padding: 12px; }
  .field-row, .compact-field { grid-template-columns: 90px minmax(0, 1fr); gap: 7px; margin-bottom: 8px; }
  .field-row input, .field-row select { min-height: 42px; padding: 6px 9px; }
  .avatar-fieldset { padding-top: 2px; margin-bottom: 8px; }
  .avatar-fieldset legend { margin-bottom: 5px; }
  .avatar-picker { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .profile-panel .secondary-command { margin-top: 6px; }
  .world-toolbar { min-height: 72px; padding: 8px 10px; }
  .toolbar-actions .xp-chip, .toolbar-actions .garage-chip, .toolbar-actions .icon-command:not(#changePlayerTopButton) { display: none; }
  .stage-map { width: calc(100% - 20px); grid-template-columns: 1fr; margin-top: 16px; }
  .stage-card { min-height: 220px; }
  .game-hud { min-height: 64px; padding: 5px 7px; }
  .hud-player img { width: 46px; height: 46px; }
  .hud-player span { font-size: 10px; }
  .hud-stat { height: 46px; min-width: 58px; }
  .hud-stat:nth-child(2) { display: none; }
  .hud-icon { width: 44px; min-height: 46px; }
  .finish-stage-button { top: 80px; }
  .stage-intro-body { grid-template-columns: 1fr; }
  .stage-intro-body > img { max-height: 220px; }
  .dialog-body { padding: 18px; }
  .math-equation { font-size: 25px; min-height: 72px; }
  .number-pad button { height: 44px; }
  .result-actions { grid-template-columns: 1fr; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
  .result-grid > div:nth-child(5) { grid-column: 1 / -1; }
  .collection-grid { grid-template-columns: repeat(2, 1fr); }
  .avatar-room-grid { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
}

@media (max-width: 359px) {
  .avatar-picker { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (pointer: coarse) and (min-width: 901px) and (orientation: landscape) {
  .profile-screen { overflow: hidden; }
  .profile-shell { height: 100dvh; min-height: 0; grid-template-columns: minmax(250px, 0.7fr) minmax(560px, 1.3fr); align-content: normal; align-items: center; padding: 14px 0; }
  .brand-block { text-align: left; }
  .creator-byline { margin-left: 0; }
  .profile-panel { max-height: calc(100dvh - 28px); overflow: auto; }
}

@media (max-height: 680px) and (orientation: landscape) {
  .profile-shell { grid-template-columns: minmax(120px, 0.45fr) minmax(0, 1.55fr); gap: 10px; align-content: center; }
  .brand-block h1 { font-size: 38px; }
  .profile-panel { max-height: calc(100dvh - 16px); padding: 10px; overflow: auto; }
  .avatar-fieldset { margin-bottom: 6px; }
  .avatar-picker { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
  .avatar-choice .capacity-label, .avatar-choice .lock-label { left: 2px; right: 2px; font-size: 8px; padding: 1px; }
  .field-row { margin-bottom: 7px; }
  .game-hud { min-height: 58px; }
  .hud-player img { width: 42px; height: 42px; }
  .hud-stat { height: 42px; }
  .hud-icon { min-height: 42px; }
  .finish-stage-button { top: 74px; }
  .math-dialog { width: min(820px, calc(100% - 18px)); }
  .math-dialog .dialog-body { display: grid; grid-template-columns: 1fr 260px; column-gap: 16px; align-items: center; padding: 14px 18px; }
  .math-dialog .dialog-kicker, .math-dialog h2, .math-equation, .answer-display, .math-feedback { grid-column: 1; }
  .number-pad { grid-column: 2; grid-row: 1 / span 5; }
  .math-dialog #submitAnswerButton { grid-column: 2; }
  .number-pad button { height: 42px; }
  .math-equation { min-height: 62px; margin: 4px 0; }
  .answer-display { min-height: 90px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .result-dialog { width: min(780px, calc(100% - 20px)); }
  .result-dialog .dialog-body { padding: 10px 14px; }
  .result-dialog .dialog-kicker { margin: 0; }
  .result-dialog h2 { margin: 0; font-size: 20px; }
  .result-stars { min-height: 32px; font-size: 27px; }
  .result-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 6px 0; }
  .result-grid > div:nth-child(5) { grid-column: auto; }
  .result-grid > div { min-height: 52px; }
  .result-grid strong { font-size: 18px; }
  .result-grid .result-score { grid-column: auto; }
  .result-grid .result-score strong { font-size: 22px; }
  .result-actions { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .result-actions button { min-height: 38px; padding: 6px 10px; }
}
