:root{
  --bg:#101418; --panel:#192027; --panel2:#222c35; --line:#33414e;
  --text:#e8eef4; --muted:#93a4b4; --accent:#f0a04b; --accent2:#4aa3df;
  --ok:#59c27a; --err:#de5b5b; --warn:#e0b04a;
}
*{box-sizing:border-box}
body{margin:0;background:radial-gradient(circle at 20% 0%,#1d2831 0,#101418 45%),var(--bg);
  color:var(--text);font:15px/1.55 system-ui,"Segoe UI","Microsoft YaHei",sans-serif}
header{display:flex;justify-content:space-between;align-items:center;padding:14px 22px;
  border-bottom:1px solid var(--line);background:rgba(16,20,24,.9);position:sticky;top:0;z-index:5}
header h1{margin:0;font-size:19px}
main{max-width:1280px;margin:20px auto;padding:0 16px 60px}
.panel{background:rgba(25,32,39,.96);border:1px solid var(--line);border-radius:14px;padding:16px;margin-bottom:16px;
  box-shadow:0 8px 24px rgba(0,0,0,.25)}
h1,h2,h3{margin:0 0 10px}
h1{font-size:26px}h2{font-size:18px}h3{font-size:15px}
.muted{color:var(--muted)}.small{font-size:12px}.bad{color:var(--err)}
b{color:#fff}
.btn{background:linear-gradient(180deg,#f4b25f,#d48735);border:none;color:#1d1206;
  padding:10px 20px;border-radius:10px;font-weight:700;cursor:pointer;font-size:15px}
.btn.big{padding:14px 30px;font-size:17px;width:100%}
.btn.secondary{background:var(--panel2);color:var(--text);border:1px solid var(--line)}
.btn:disabled{opacity:.4;cursor:not-allowed}
.row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.start-card{max-width:760px;margin:6vh auto 0;text-align:center}
.mode-picker{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin:18px 0}
.mode-card{background:var(--panel2);border:1px solid var(--line);color:var(--text);border-radius:12px;
  padding:16px;text-align:left;cursor:pointer;display:flex;flex-direction:column;gap:5px}
.mode-card.active{border-color:var(--accent);box-shadow:0 0 0 2px rgba(240,160,75,.25)}
.mode-card b{font-size:16px}.mode-card span{font-size:12px;color:var(--muted)}
.rules{text-align:left;display:grid;gap:4px;margin:12px 0;font-size:14px}
.hud{display:flex;align-items:center;gap:22px;flex-wrap:wrap;padding:12px 18px}
.hud b{color:#fff}.timer{min-width:230px;margin-left:auto;display:flex;align-items:center;gap:10px}
.timer-bar{height:12px;flex:1;background:#0d1116;border:1px solid var(--line);border-radius:99px;overflow:hidden}
.timer-bar i{display:block;height:100%;width:100%;background:linear-gradient(90deg,#59c27a,#e0b04a);
  transition:width .1s linear}
.timer-bar i.low{background:linear-gradient(90deg,#e0b04a,#de5b5b)}
.game-grid{display:grid;grid-template-columns:minmax(0,1.25fr) minmax(310px,1fr);gap:16px;align-items:start}
.palette{display:grid;grid-template-columns:repeat(auto-fill,minmax(96px,1fr));gap:9px;max-height:66vh;overflow:auto;padding-right:4px}
.ingredient{margin:0;background:var(--panel2);border:1px solid var(--line);border-radius:11px;
  padding:9px 5px;text-align:center;cursor:pointer;transition:transform .08s,border-color .08s}
.ingredient:hover{border-color:var(--accent);transform:translateY(-2px)}
.ingredient img,.slot img,.prediction-item img,.history-dish img,.dish-chip img{image-rendering:pixelated}
.ingredient img{width:46px;height:46px;display:block;margin:0 auto}
.ingredient figcaption{font-size:12px;margin-top:5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.noicon{display:inline-flex;width:46px;height:46px;align-items:center;justify-content:center;
  border:1px dashed var(--line);border-radius:9px;color:var(--muted)}
.cooker-row{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:10px;align-items:center}
.cooker{background:var(--panel2);border:1px solid var(--line);color:var(--text);border-radius:9px;
  padding:7px 12px;cursor:pointer}
.cooker.active{border-color:var(--accent);color:var(--accent);font-weight:700}
.slots{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-bottom:14px}
.slot{min-height:102px;border:1px dashed var(--line);border-radius:11px;background:var(--panel2);
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:7px 4px;
  font-size:12px;text-align:center;cursor:pointer}
.slot.empty{color:var(--muted);cursor:default}
.slot:not(.empty):hover{border-color:var(--err);color:var(--err)}
.slot img{width:42px;height:42px}
.prediction-list{display:grid;gap:6px;margin-bottom:14px;max-height:220px;overflow:auto}
.prediction-item{display:flex;align-items:center;gap:8px;background:var(--panel2);border:1px solid var(--line);
  border-radius:9px;padding:6px 9px;font-size:13px}
.prediction-item.new{border-color:var(--ok)}
.prediction-item.old{opacity:.68}
.prediction-item img{width:32px;height:32px}
.prediction-item em{margin-left:auto;font-style:normal;font-size:11px;color:var(--muted)}
.history-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(84px,1fr));gap:8px}
.history-dish{margin:0;background:var(--panel2);border:1px solid var(--line);border-radius:10px;
  padding:7px 4px;text-align:center;font-size:11px}
.history-dish img{width:40px;height:40px;display:block;margin:0 auto}
.history-dish figcaption{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:3px}
.modal-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.65);display:flex;align-items:center;
  justify-content:center;z-index:50;padding:calc(16px + env(safe-area-inset-top,0px)) 16px calc(16px + env(safe-area-inset-bottom,0px));
  overflow-y:auto;overscroll-behavior:contain}
.modal{max-width:520px;width:100%;text-align:center;
  max-height:calc(100vh - 32px);max-height:calc(100dvh - 32px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));
  overflow-y:auto;overscroll-behavior:contain}
.score{font-size:22px;color:var(--accent)}
.modal-dishes{display:flex;flex-wrap:wrap;gap:6px;justify-content:center;margin:14px 0}
.dish-chip{display:inline-flex;align-items:center;gap:5px;background:var(--panel2);border:1px solid var(--line);
  padding:4px 8px;border-radius:99px;font-size:12px}
.dish-chip img{width:24px;height:24px}
.toast{position:fixed;left:50%;bottom:32px;transform:translateX(-50%);background:#1e2a34;border:1px solid var(--ok);
  color:#fff;padding:12px 20px;border-radius:12px;z-index:80;display:none;box-shadow:0 10px 30px rgba(0,0,0,.4);
  max-width:80vw;text-align:center}
.toast.error{border-color:var(--err)}
/* ------------------------------------------------------------------ *
 * Full-viewport game mode
 *
 * The in-game view is a fixed-height flex column: compact HUD, board
 * (ingredient palette + cooking panel), and a thin history strip. Long
 * lists scroll inside their own panel, never the page, so the whole game
 * UI stays visible without scrolling on a phone.
 * ------------------------------------------------------------------ */
html { height: 100%; }
body { min-height: 100%; -webkit-tap-highlight-color: transparent; }
.btn, .ingredient, .slot, .cooker, .mode-card { touch-action: manipulation; }

body[data-view="game"] {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}
body[data-view="game"] main {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body[data-view="game"] #app {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) minmax(0, auto);
  gap: 10px;
}
body[data-view="game"] .hud { margin: 0; }
body[data-view="game"] .game-grid { min-height: 0; align-items: stretch; }
body[data-view="game"] .game-grid > .panel {
  min-height: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body[data-view="game"] .palette {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  align-content: flex-start;
  overscroll-behavior: contain;
}
body[data-view="game"] .cook-panel {
  overflow-y: auto;
  overscroll-behavior: contain;
}
body[data-view="game"] .history-panel {
  min-height: 0;
  max-height: clamp(96px, 16dvh, 160px);
  overflow: hidden;
}
body[data-view="game"] .history-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  align-content: flex-start;
  overscroll-behavior: contain;
}

/* Mobile portrait / narrow screens: stack the board and tighten controls. */
@media (max-width: 900px) {
  body[data-view="game"] header { display: none; }
  body[data-view="game"] main {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  body[data-view="game"] #app { gap: 6px; }

  body[data-view="game"] .hud {
    gap: 6px;
    padding: 6px 9px;
    border-radius: 10px;
    font-size: 12px;
    flex-wrap: nowrap;
  }
  body[data-view="game"] .hud > div { white-space: nowrap; }
  body[data-view="game"] .hud .timer {
    min-width: 0;
    margin-left: auto;
    gap: 5px;
    flex: 1 1 92px;
  }
  body[data-view="game"] .timer-bar { height: 8px; }

  body[data-view="game"] .game-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    overflow: hidden;
  }
  body[data-view="game"] .game-grid > .palette-panel { flex: 1 1 0; min-height: 96px; }
  body[data-view="game"] .game-grid > .cook-panel {
    flex: 0 1 auto;
    max-height: 58%;
    padding: 8px;
  }
  body[data-view="game"] .game-grid > .panel { padding: 8px; }
  body[data-view="game"] .game-grid h2 { font-size: 13px; margin-bottom: 5px; }
  body[data-view="game"] .game-grid h3 { font-size: 12px; margin-bottom: 4px; }

  body[data-view="game"] .palette {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
    padding-right: 1px;
    align-content: flex-start;
  }
  body[data-view="game"] .ingredient { padding: 3px; border-radius: 8px; }
  body[data-view="game"] .ingredient img { width: 32px; height: 32px; }
  body[data-view="game"] .ingredient figcaption { font-size: 10px; line-height: 1.1; margin-top: 2px; }
  body[data-view="game"] .noicon { width: 32px; height: 32px; border-radius: 7px; }

  /* 13+ ingredients need one more column and smaller cards to stay visible. */
  body[data-view="game"] .palette.dense { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  body[data-view="game"] .palette.dense .ingredient { padding: 2px; }
  body[data-view="game"] .palette.dense .ingredient img { width: 24px; height: 24px; }
  body[data-view="game"] .palette.dense .ingredient figcaption { font-size: 9px; line-height: 1; margin-top: 1px; }
  body[data-view="game"] .palette.dense .noicon { width: 24px; height: 24px; }

  body[data-view="game"] .cooker-row { gap: 5px; margin-bottom: 6px; }
  body[data-view="game"] .cooker { padding: 5px 8px; border-radius: 7px; font-size: 11px; }
  body[data-view="game"] .cooker img { width: 20px; height: 20px; margin-right: 3px; }
  body[data-view="game"] .cooker-row > .muted { display: none; }

  body[data-view="game"] .slots { gap: 5px; margin-bottom: 6px; }
  body[data-view="game"] .slot {
    min-height: 52px;
    padding: 3px 2px;
    gap: 2px;
    border-radius: 8px;
    font-size: 10px;
  }
  body[data-view="game"] .slot img { width: 28px; height: 28px; }

  body[data-view="game"] #prediction { min-height: 18px; }
  body[data-view="game"] #prediction > p { margin: 0; font-size: 11px; }
  /* Prediction results wrap as compact chips instead of a tall vertical
     list. Ties are rare, but a few dishes still stay above the fold. */
  body[data-view="game"] .prediction-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 0;
    max-height: none;
    overflow: visible;
  }
  body[data-view="game"] .prediction-item {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    gap: 4px;
    padding: 3px 6px;
    font-size: 11px;
  }
  body[data-view="game"] .prediction-item span {
    min-width: 0;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  body[data-view="game"] .prediction-item img { width: 20px; height: 20px; }
  body[data-view="game"] .prediction-item em { margin-left: 1px; font-size: 9px; }

  body[data-view="game"] #cookBtn { padding: 9px 12px; border-radius: 8px; font-size: 14px; }
  body[data-view="game"] #submitHint { min-height: 14px; margin: 3px 0 0; font-size: 10px; }

  body[data-view="game"] .history-panel {
    max-height: clamp(54px, 9dvh, 80px);
    padding: 5px 8px;
    border-radius: 10px;
  }
  body[data-view="game"] .history-panel h2 {
    font-size: 11px;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body[data-view="game"] .history-grid {
    display: flex;
    flex-wrap: nowrap;
    gap: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 1px;
    align-content: initial;
  }
  body[data-view="game"] .history-dish {
    flex: 0 0 50px;
    padding: 2px;
    border-radius: 7px;
    font-size: 9px;
  }
  body[data-view="game"] .history-dish img { width: 26px; height: 26px; }
  body[data-view="game"] .history-dish figcaption { font-size: 9px; margin-top: 1px; }
  body[data-view="game"] .history-grid > .muted { margin: 2px 0; font-size: 11px; }

  /* Start screen also stays comfortable on a phone. */
  body[data-view="start"] {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  header { padding: 8px 12px; }
  header h1 { font-size: 15px; }
  body[data-view="start"] .brand-portrait { width: 22px; height: 20px; margin-right: 5px; }
  body[data-view="start"] main {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0 auto;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
  }
  .start-card {
    flex: 0 1 auto;
    width: 100%;
    min-height: 0;
    max-height: 100%;
    margin: 0 auto;
    padding: 14px;
    overflow-y: auto;
  }
  body[data-view="start"] .start-portrait { width: 96px; height: 84px; margin-bottom: 4px; }
  .start-card h1 { font-size: 20px; margin-bottom: 6px; }
  .start-card p { margin: 5px 0; }
  .start-card p.muted { font-size: 12px; }
  .mode-picker { gap: 8px; margin: 10px 0; }
  .mode-card { padding: 10px; }
  .rules { font-size: 12px; margin: 8px 0; }
  .btn.big { padding: 11px 16px; font-size: 15px; }
}

/* Very narrow phones (320-340 px): shrink cards further so all 9
   ingredients in a default round still fit without an inner palette scroll. */
@media (max-width: 340px) {
  body[data-view="game"] main { padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); }
  body[data-view="game"] .hud { gap: 4px; padding: 4px 6px; font-size: 11px; }
  body[data-view="game"] .hud .timer { gap: 4px; flex-basis: 74px; }
  body[data-view="game"] .game-grid > .panel { padding: 6px; }
  body[data-view="game"] .game-grid h2 { font-size: 11px; margin-bottom: 3px; }
  body[data-view="game"] .game-grid h3 { font-size: 11px; margin-bottom: 3px; }
  body[data-view="game"] .palette { gap: 4px; }
  body[data-view="game"] .ingredient { padding: 3px 2px; }
  body[data-view="game"] .ingredient img { width: 27px; height: 27px; }
  body[data-view="game"] .ingredient figcaption { font-size: 9px; line-height: 1.1; margin-top: 1px; }
  body[data-view="game"] .noicon { width: 27px; height: 27px; }
  body[data-view="game"] .palette.dense { gap: 3px; }
  body[data-view="game"] .palette.dense .ingredient { padding: 2px 1px; }
  body[data-view="game"] .palette.dense .ingredient img { width: 21px; height: 21px; }
  body[data-view="game"] .palette.dense .ingredient figcaption { font-size: 8px; margin-top: 0; }
  body[data-view="game"] .palette.dense .noicon { width: 21px; height: 21px; }
  body[data-view="game"] .cooker-row { gap: 4px; margin-bottom: 5px; }
  body[data-view="game"] .cooker { padding: 4px 6px; font-size: 10px; }
  body[data-view="game"] .cooker img { width: 17px; height: 17px; margin-right: 2px; }
  body[data-view="game"] .slots { gap: 4px; margin-bottom: 5px; }
  body[data-view="game"] .slot { min-height: 44px; font-size: 9px; }
  body[data-view="game"] .slot img { width: 24px; height: 24px; }
  body[data-view="game"] #prediction > p { font-size: 10px; }
  body[data-view="game"] .prediction-item { padding: 3px 5px; font-size: 10px; }
  body[data-view="game"] .prediction-item img { width: 20px; height: 20px; }
  body[data-view="game"] #cookBtn { padding: 7px 10px; font-size: 13px; }
  body[data-view="game"] #submitHint { font-size: 9px; }
  body[data-view="game"] .history-panel { max-height: 48px; }
  body[data-view="game"] .history-dish { flex-basis: 44px; }
  body[data-view="game"] .history-dish img { width: 22px; height: 22px; }

  /* Keep the setup card fully on-screen on 320x568 phones too. */
  body[data-view="start"] header { padding: 6px 10px; }
  header h1 { font-size: 14px; }
  body[data-view="start"] .brand-portrait { width: 20px; height: 18px; margin-right: 4px; }
  .start-card { padding: 10px; }
  body[data-view="start"] .start-portrait { width: 78px; height: 68px; margin-bottom: 2px; }
  .start-card h1 { font-size: 18px; margin-bottom: 4px; }
  .start-card p { margin: 4px 0; }
  .start-card p.muted { font-size: 11px; }
  .mode-picker { gap: 6px; margin: 8px 0; }
  .mode-card { padding: 8px; gap: 3px; }
  .mode-card b { font-size: 14px; }
  .mode-card span { font-size: 11px; }
  .rules { font-size: 11px; margin: 6px 0; gap: 2px; }
  .btn.big { padding: 9px 12px; font-size: 14px; }
}

/* Short landscape phones: keep the two board panels side by side and
   hide the decorative header/history so gameplay still fits one screen. */
@media (orientation: landscape) and (max-height: 560px) and (max-width: 1000px) {
  body[data-view="game"] header { display: none; }
  body[data-view="game"] main { padding: 5px 8px calc(5px + env(safe-area-inset-bottom, 0px)); }
  body[data-view="game"] #app { gap: 5px; grid-template-rows: auto minmax(0, 1fr) auto; }
  body[data-view="game"] .game-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(250px, 1fr);
    gap: 6px;
  }
  body[data-view="game"] .game-grid > .palette-panel { min-height: 0; }
  body[data-view="game"] .game-grid > .cook-panel { max-height: none; }
  body[data-view="game"] .palette { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); }
  body[data-view="game"] .history-panel { display: none; }
  body[data-view="game"] .hud { padding: 4px 8px; font-size: 11px; }
}


.solution{margin:14px 0 4px;padding:12px;border:1px solid var(--warn);border-radius:12px;
  background:rgba(224,176,74,.08);text-align:left}
.solution h3{margin:0 0 8px}
.solution-ingredients{display:flex;flex-wrap:wrap;gap:6px;justify-content:center}
.solution p{margin:8px 0 0;text-align:center}

.brand-portrait{width:30px;height:26px;object-fit:contain;vertical-align:middle;margin-right:8px;
  image-rendering:pixelated}
.start-portrait{display:block;width:150px;height:130px;object-fit:contain;margin:0 auto 8px;
  image-rendering:pixelated}
.cooker img{width:26px;height:26px;object-fit:contain;vertical-align:middle;margin-right:5px;
  image-rendering:pixelated}

/* Portrait phones: the palette sizes to its content instead of absorbing
   every free pixel, and the history panel receives the remaining height.
   Wrapped rows replace the old single-line horizontal scroller. */
@media (orientation: portrait) and (max-width: 900px) {
  body[data-view="game"] #app {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  body[data-view="game"] .hud { flex: 0 0 auto; }
  body[data-view="game"] .game-grid {
    flex: 0 1 auto;
    min-height: 0;
    overflow: hidden;
  }
  body[data-view="game"] .game-grid > .palette-panel {
    flex: 0 1 auto;
    min-height: 0;
  }
  body[data-view="game"] .game-grid > .cook-panel {
    flex: 0 0 auto;
    max-height: none;
  }
  body[data-view="game"] .history-panel {
    flex: 1 1 0;
    min-height: 56px;
    max-height: none;
    display: flex;
    flex-direction: column;
  }
  body[data-view="game"] .history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    grid-auto-rows: min-content;
    gap: 4px;
    overflow-x: hidden;
    overflow-y: auto;
    padding-bottom: 0;
    align-content: flex-start;
  }
  body[data-view="game"] .history-dish {
    flex: none;
    width: auto;
    min-width: 0;
    padding: 2px 1px;
    font-size: 9px;
  }
  body[data-view="game"] .history-dish img { width: 24px; height: 24px; }
  body[data-view="game"] .history-dish figcaption { margin-top: 1px; }
}
