:root {
  --bg-top: #f2d7a5;
  --bg-bottom: #d98756;
  --card: rgba(78, 43, 21, 0.9);
  --card-border: rgba(255, 227, 167, 0.42);
  --panel: rgba(255, 244, 214, 0.88);
  --panel-text: #3d2414;
  --accent: #ff9e53;
  --accent-strong: #d85d37;
  --mint: #6db8ad;
  --rain: #4a83b8;
  --danger: #a83232;
  --ink: #24150c;
  --soft-shadow: 0 18px 40px rgba(60, 25, 9, 0.28);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  color: #fff7e9;
  background:
    radial-gradient(circle at top left, rgba(255, 244, 214, 0.72), transparent 38%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 12px
    max(12px, env(safe-area-inset-bottom)) 12px;
}

.game-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
}

.game-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: calc(100dvh - 24px);
  max-height: calc(100dvh - 24px);
  padding: 12px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(95, 47, 20, 0.95), rgba(57, 28, 16, 0.95));
  border: 1px solid var(--card-border);
  box-shadow: var(--soft-shadow);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.status-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 54px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--panel-text);
  background: var(--panel);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.status-chip small {
  font-size: 0.68rem;
  opacity: 0.72;
}

.status-chip--weather {
  color: #17304e;
}

.status-icon {
  width: 26px;
  height: 26px;
  flex: none;
}

.playfield-frame {
  display: grid;
  place-items: center;
  position: relative;
  flex: 1 1 auto;
  min-height: 240px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 24px;
  border: 2px solid rgba(255, 224, 165, 0.16);
  background:
    linear-gradient(180deg, rgba(239, 203, 139, 0.35), rgba(129, 68, 35, 0.4)),
    #2f1a10;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(38, 19, 11, 0.48);
  backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(100%, 460px);
  padding: 18px 18px 20px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 245, 217, 0.95), rgba(250, 229, 176, 0.94));
  color: var(--ink);
  box-shadow: 0 16px 32px rgba(51, 25, 10, 0.22);
}

.overlay-card h1 {
  margin: 4px 0 10px;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  line-height: 1;
}

.overlay-card p {
  margin: 0;
}

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  opacity: 0.72;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.primary-button,
.secondary-button,
.action-button {
  border: none;
  border-radius: 18px;
  padding: 14px 12px;
  cursor: pointer;
  transition:
    transform 140ms ease,
    filter 140ms ease,
    opacity 140ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.action-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  flex: 1;
  color: #fff7ea;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16);
}

.secondary-button {
  min-width: 112px;
  color: #17304e;
  background: rgba(128, 189, 207, 0.96);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meta-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.meta-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 239, 205, 0.12);
  color: #fff5dd;
}

.order-caption {
  display: none;
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  margin: 0;
  padding: 8px;
  font-size: 14px;
  line-height: 1.4;
  background: #fff8e6;
  color: #352818;
  pointer-events: none;
}

@media (max-width: 640px) {
  .order-caption:not(:empty) { display: block; }
}

.meta-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.76;
}

.meta-value {
  min-width: 0;
  text-align: right;
  line-height: 1.15;
}

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

.action-button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  min-height: 66px;
  color: #fff7ea;
  background: rgba(255, 232, 181, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 238, 200, 0.12);
}

.action-button small {
  font-size: 0.74rem;
  opacity: 0.72;
}

.action-button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

.danger-button {
  background: rgba(168, 50, 50, 0.24);
}

.mode-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 8px 12px;
  border-radius: 999px;
  color: #17304e;
  background: rgba(179, 220, 236, 0.94);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.toast {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  min-width: min(92%, 360px);
  padding: 12px 14px;
  border-radius: 16px;
  text-align: center;
  color: #fff7ea;
  background: rgba(39, 19, 11, 0.84);
  box-shadow: 0 12px 24px rgba(26, 10, 5, 0.28);
}

.hidden {
  display: none;
}

@media (max-width: 900px) {
  .game-card {
    min-height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
    padding: 10px;
  }

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

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

@media (max-width: 640px) {
  .app-shell {
    padding-inline: 8px;
  }

  .game-card {
    gap: 8px;
    padding: 8px;
    border-radius: 22px;
  }

  .status-strip {
    gap: 6px;
  }

  .status-chip {
    min-height: 48px;
    padding: 8px;
    font-size: 0.86rem;
  }

  .status-chip small {
    display: none;
  }

  .meta-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .meta-pill {
    padding: 9px 10px;
  }

  .action-grid {
    gap: 6px;
  }

  .action-button {
    min-height: 60px;
    padding: 12px 10px;
    font-size: 0.96rem;
  }

  .overlay-card {
    padding: 16px;
  }

  .overlay-actions {
    flex-direction: column;
  }
}
#game-canvas-3d {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  touch-action: manipulation;
}

#game-canvas[hidden], #game-canvas-3d[hidden] { display: none; }
.view-control { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.view-control select { padding: 5px 12px; font: inherit; }
.view-control[hidden] { display: none; }
.view-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
#view-zoom { width: 90px; accent-color: #57b9b4; }
.playfield-frame:has(#game-canvas-3d:not([hidden])) .order-caption:not(:empty) { display: block; }

[hidden] { display: none !important; }
button, select, input { font:inherit; }
button, a, select, input { -webkit-tap-highlight-color:transparent; }
button:focus-visible, a:focus-visible, select:focus-visible { outline:2px solid #24796b; outline-offset:2px; }
.game-header { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; gap:8px; }
.header-actions { display:flex; gap:4px; }
.icon-button { display:grid; place-items:center; width:44px; height:44px; flex:none; border:1px solid #c5d3cf; border-radius:6px; background:#fff; padding:10px; cursor:pointer; }
.icon-button img { width:22px; height:22px; pointer-events:none; }
.icon-button:disabled { opacity:.4; cursor:default; }
.game-header .status-strip { grid-template-columns:repeat(3,minmax(0,1fr)); gap:4px; }
.game-header .status-chip { min-height:40px; min-width:0; padding:4px; gap:4px; font-size:14px; letter-spacing:0; text-transform:none; white-space:nowrap; border-radius:4px; }
.game-header .status-icon { width:20px; height:20px; }
.status-chip span { font-variant-numeric:tabular-nums; }
.mode-links { display:flex; justify-content:space-between; gap:12px; font-size:13px; }
.mode-links a { color:inherit; padding:10px 0; }
#settings-dialog { width:min(440px,calc(100% - 24px)); max-height:calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow:auto; overscroll-behavior:contain; padding:16px; border:1px solid #b7cbc3; border-radius:8px; color:#233c36; background:#f8fbfa; box-shadow:0 12px 48px #173c3540; }
#settings-dialog::backdrop { background:#16382f80; }
.settings-heading { position:sticky; top:-16px; z-index:1; display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:12px; background:#f8fbfa; }
.settings-heading h2 { font-size:20px; margin:0; }
#settings-dialog .control-panel { gap:12px; border:0; padding:0; }
#settings-dialog .view-toolbar { gap:12px; }
#settings-dialog .view-control { margin:0; font-size:13px; min-height:44px; }
#settings-dialog select { min-height:44px; font-size:16px; border:1px solid #b7cbc3; border-radius:4px; background:#fff; }
#settings-dialog .meta-row { grid-template-columns:1fr 1fr; gap:0 16px; }
#settings-dialog .meta-pill { background:none; color:inherit; border-radius:0; font-size:13px; padding:8px 0; gap:6px; }
#settings-dialog .meta-label { font-size:11px; letter-spacing:0; text-transform:none; }
#settings-dialog .action-grid { grid-template-columns:repeat(3,minmax(0,1fr)); gap:6px; }
#settings-dialog .action-button { background:#fff; color:#244338; border:1px solid #c3d3cb; border-radius:6px; min-height:54px; font-size:13px; padding:8px; box-shadow:none; }
#settings-dialog .action-button small { font-size:11px; }
#settings-dialog .danger-button { color:#aa3934; min-height:44px; background:none; align-items:center; }
#settings-progress { margin:0; line-height:1.5; font-size:13px; }
.story-mode { background:#eef3f1; color:#223b36; }
.story-mode * { letter-spacing:0; }
.story-mode .app-shell { height:100dvh; min-height:0; padding:max(8px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left)); }
.story-mode .game-shell { width:min(100%,1120px); height:100%; }
.story-mode .game-card { height:100%; min-height:0; max-height:none; display:grid; grid-template-rows:44px 20px minmax(0,1fr) 96px; gap:4px; background:none; border:0; border-radius:0; padding:0; box-shadow:none; }
.story-mode .status-chip { background:none; color:#24413b; }
#chapter-band { display:flex; align-items:center; justify-content:space-between; gap:8px; min-width:0; font-size:13px; line-height:20px; }
#chapter-title { white-space:nowrap; }
#hud-time { font-variant-numeric:tabular-nums; }
.story-mode #hud-time { color:#576e64; }
.streak-status { display:flex; align-items:center; gap:3px; min-width:32px; justify-content:end; }
.streak-status img { width:16px; height:16px; }
#chapter-progress { font-size:12px; font-variant-numeric:tabular-nums; }
.story-mode .playfield-frame { container-type:size; grid-template-columns:minmax(0,1fr); grid-template-rows:minmax(0,1fr); width:100%; height:100%; min-height:0; border:0; border-radius:0; aspect-ratio:auto; background:#a9d8dc; }
.story-mode .playfield-frame canvas { min-width:0; min-height:0; width:min(100cqw,177.7778cqh); height:auto; aspect-ratio:16/9; }
.story-mode .playfield-frame #game-canvas-3d { width:100%; height:100%; aspect-ratio:auto; }
.story-mode .overlay { background:#173c3540; backdrop-filter:blur(2px); padding:8px; z-index:3; }
.story-mode .overlay-card { background:#fff; border-radius:8px; max-height:100%; overflow:auto; padding:12px; }
.story-mode .overlay-card h1 { font-size:22px; line-height:1.1; margin:4px 0 8px; }
.story-mode .overlay-card p { font-size:13px; line-height:1.4; }
.story-mode .primary-button { min-height:44px; background:#24796b; box-shadow:none; border-radius:4px; padding:10px; }
.story-mode .overlay-actions { margin-top:10px; flex-direction:row; }
.story-mode .order-caption { display:none !important; }
.story-mode .toast { padding:6px 10px; font-size:12px; border-radius:4px; min-width:0; width:max-content; max-width:90%; background:#183b35ed; }
#story-panel { position:relative; display:grid; grid-template-rows:48px 44px; gap:4px; min-width:0; }
.order-list { display:flex; gap:6px; overflow-x:auto; overflow-y:hidden; min-width:0; max-width:100%; scrollbar-width:thin; scroll-snap-type:x proximity; }
.order-list:empty::before { content:'Đợi khách'; align-self:center; color:#78857f; font-size:12px; }
.order-list button { display:flex; align-items:center; gap:4px; flex:0 0 150px; height:44px; min-width:0; padding:2px 5px; background:#fff; border:1px solid #becbc5; border-radius:4px; color:#233e35; text-align:left; scroll-snap-align:start; cursor:pointer; }
.order-list img { width:24px; height:36px; object-fit:contain; }
.order-list span { white-space:pre-line; font-size:11px; line-height:1.25; }
.story-mode [aria-pressed="true"] { outline:2px solid #237f70; outline-offset:-2px; }
.preparation-row { display:grid; grid-template-rows:44px 58px 44px; gap:6px; min-width:0; }
.recipe-picker { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:4px; padding:0; border:0; margin:0; min-width:0; }
.recipe-picker legend { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
.recipe-picker label { display:flex; align-items:center; justify-content:center; gap:4px; min-width:0; height:44px; padding:3px; font-size:12px; border-bottom:3px solid transparent; cursor:pointer; }
.recipe-picker label:has(:checked) { background:#d8eae2; border-color:#257968; }
.recipe-picker label:has(:disabled) { opacity:.4; cursor:default; }
.recipe-picker input { position:absolute; opacity:0; width:1px; height:1px; }
.recipe-picker label:has(:focus-visible) { outline:2px solid #24796b; }
.recipe-picker img { width:24px; height:32px; flex:none; }
.recipe-options { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:6px; align-items:end; }
.preparation-actions { display:grid; grid-template-columns:minmax(0,1fr) 76px; gap:8px; align-items:end; }
.serving-picker { display:grid; grid-template-columns:repeat(3,minmax(44px,1fr)); gap:4px; margin:0; border:0; padding:0; min-width:0; }
.serving-picker legend { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
.serving-picker label { display:grid; place-items:center; height:44px; font-size:12px; border-bottom:3px solid transparent; cursor:pointer; }
.serving-picker label:has(:checked) { background:#d8eae2; border-color:#257968; }
.serving-picker label:has(:focus-visible) { outline:2px solid #24796b; }
.serving-picker input { position:absolute; opacity:0; width:1px; height:1px; }
.recipe-options label { display:flex; flex-direction:column; gap:2px; font-size:10px; line-height:12px; min-width:0; }
.recipe-options select { width:100%; min-width:0; height:44px; font-size:16px; border:1px solid #b1c5bb; padding:4px 6px; background:white; border-radius:4px; }
#prepare-drink,#deliver-drink { height:44px; min-width:0; background:#267d6c; color:white; border:0; border-radius:4px; padding:8px; font-size:14px; cursor:pointer; }
#deliver-drink { background:#c6574c; height:44px; font-size:12px; }
.tray-row { display:grid; grid-template-columns:44px minmax(0,1fr) minmax(0,1fr) 44px 64px; gap:4px; min-width:0; }
.batch-slot { position:relative; min-width:0; height:44px; border:1px solid #bac8bf; border-radius:4px; background:#fff; color:#25493d; font-size:10px; line-height:12px; padding:3px; white-space:pre-line; overflow-wrap:anywhere; cursor:pointer; }
.batch-slot::after { content:''; position:absolute; bottom:0; left:0; height:3px; width:var(--brew-progress,0%); background:#3d9680; }
#discard-drink { height:44px; background:transparent; }
#story-feedback { position:absolute; bottom:104px; left:8px; max-width:calc(100% - 16px); margin:0; padding:4px 8px; font-size:11px; line-height:15px; color:#233b35; background:#fffffff0; border-radius:4px; pointer-events:none; }
#story-feedback:empty { display:none; }
.story-mode button:disabled { opacity:.45; cursor:default; }
@media(min-width:900px) {
  .story-mode .app-shell { padding:12px; }
  .story-mode .game-shell { width:min(100%,1440px); }
  .story-mode #story-panel { grid-template-columns:minmax(0,1fr) 360px; grid-template-rows:48px; }
  .story-mode .game-card { grid-template-rows:44px 20px minmax(0,1fr) 48px; }
  #story-feedback { bottom:56px; }
}
@media(max-width:899px) and (orientation:landscape) {
  .story-mode .app-shell { padding:max(4px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) max(4px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left)); }
  .story-mode .game-card { grid-template-columns:minmax(0,1fr); grid-template-rows:44px minmax(0,1fr) 48px; }
  .story-mode #chapter-band { position:absolute; top:50px; left:16px; right:16px; z-index:1; pointer-events:none; }
  .story-mode #story-panel { grid-template-columns:minmax(0,1fr) 304px; grid-template-rows:48px; }
  .story-mode #story-feedback { bottom:56px; }
}
@media(max-width:350px) and (orientation:portrait) {
  .game-header { gap:4px; }
  .game-header .status-chip { font-size:12px; gap:2px; }
  .game-header .status-icon { width:17px; height:17px; }
  .recipe-picker label { font-size:11px; }
  .recipe-picker img { width:21px; }
  .story-mode .overlay-card h1 { font-size:18px; margin:3px 0; }
  .story-mode .overlay-card p { font-size:12px; line-height:1.3; }
}
#open-preparation { display:grid; place-items:center; width:44px; height:44px; padding:10px; border:0; border-radius:4px; background:#267d6c; cursor:pointer; }
#open-preparation img { width:24px; height:24px; filter:invert(1); }
#open-preparation span { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
#preparation-dialog,#event-dialog { color:#233c36; background:#f8fbfa; border:1px solid #b7cbc3; border-radius:8px; width:min(420px,calc(100% - 20px)); max-height:calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow:auto; padding:14px; overscroll-behavior:contain; }
#preparation-dialog { margin:auto auto max(10px,env(safe-area-inset-bottom)); }
#preparation-dialog::backdrop { background:#16382f30; }
#event-dialog::backdrop { background:#16382f60; }
#preparation-order { font-size:13px; line-height:1.4; margin:8px 0; }
#preparation-dialog .settings-heading,#event-dialog .settings-heading { top:-14px; margin:0; }
#event-dialog .settings-heading h2 { font-size:18px; }
#event-portrait { display:block; width:100%; height:130px; object-fit:contain; background:#e2efec; border-radius:4px; margin:10px 0; }
#event-text { font-size:15px; line-height:1.55; margin:12px 0; }
#event-effect { font-size:12px; color:#296a59; line-height:1.5; }
#event-choices { display:grid; gap:6px; }
#event-choices button,#event-continue { text-align:left; min-height:44px; padding:10px 12px; color:#234338; background:#fff; border:1px solid #b3cbbf; border-radius:4px; font-size:14px; line-height:1.4; cursor:pointer; }
#event-continue { width:100%; background:#267d6c; color:white; text-align:center; }
#street-event { position:absolute; top:30px; left:8px; z-index:2; max-width:calc(100% - 16px); min-height:44px; padding:8px 12px; border:1px solid #fff; border-radius:4px; background:#b74755; color:white; box-shadow:0 2px 8px #0002; font-size:12px; line-height:1.3; cursor:pointer; }
#street-progress,#street-journal { margin:0; font-size:13px; line-height:1.5; }
#street-journal summary { cursor:pointer; min-height:44px; align-content:center; }
#street-history { padding-left:20px; max-height:180px; overflow:auto; }
#street-history li { margin:8px 0; }
@media(max-height:450px) { #event-portrait { height:72px; } #event-dialog { width:min(540px,calc(100% - 20px)); } }
