* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    margin: 0;
    color: rgba(255, 255, 255, 0.9);
    background: #1a0f08;
    font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

#app {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at 50% 20%, #3a2416 0%, #1a0f08 70%);
    position: relative;
}

#game-container {
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
}
#game-container canvas {
    display: block;
}

/* ------------------------------------------------------------------ */
/* OVERLAY BASE                                                        */
/* ------------------------------------------------------------------ */
.overlay {
    position: absolute;
    z-index: 100;
    inset: 0;
    display: flex;
    /* we constrain by aspect ratio below */
}
.overlay.dim { background: rgba(15, 8, 4, 0.72); align-items: center; justify-content: center; }

/* Keep all overlays in a phone-like frame on a wide desktop screen */
@media (min-aspect-ratio: 1/1) {
    .overlay, #game-container canvas { max-width: min(100vw, 62vh); margin: 0 auto; }
}

/* ================================================================== */
/* HUD                                                                */
/* ================================================================== */
.hud {
    top: 4px;
    left: 0; right: 0;
    height: auto;
    flex-direction: column;
    pointer-events: none;
}
.hud-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 2px 6px;
    pointer-events: auto;
    flex-wrap: nowrap;
}
.hud-cell { min-width: 0; text-align: center; }
.hud-cell.center { flex: 1; }
.hud-label { font-size: 7px; text-transform: uppercase; letter-spacing: 0.5px; color: #d9b36a; line-height: 1; }
.hud-value { font-size: 13px; font-weight: 800; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.5); line-height: 1.15; }
.hud-value.gold { color: #ffd94a; }
.hud-mid {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 0 6px;
    margin-top: 1px;
    flex-wrap: nowrap;
}
.hud-pill {
    background: rgba(30, 12, 4, 0.78);
    border: 1px solid #d4af37;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 9px;
    font-weight: 700;
    color: #ffe9b0;
    white-space: nowrap;
}
.hud-pill.combo { border-color: #f5b800; color: #ffd94a; }
.hud-pill.clock { border-color: #078930; color: #aef0c4; }

.floaters {
    position: absolute;
    top: 64px;
    right: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
}
.floater {
    background: rgba(30, 12, 4, 0.9);
    border: 1px solid #f5b800;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 12px;
    color: #ffd94a;
    animation: floatUp 1.5s ease-out forwards;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.floater.loss { border-color: #da121a; color: #ff9c9c; }
@keyframes floatUp { from { opacity: 0; transform: translateY(8px); } 20% { opacity: 1; } to { opacity: 0; transform: translateY(-34px); } }

/* ================================================================== */
/* GLOBAL BUTTONS                                                      */
/* ================================================================== */
.btn {
    min-height: 48px;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 800;
    color: #2c1810;
    background: linear-gradient(180deg, #ffe08a, #f5b800);
    box-shadow: 0 3px 0 #b8860b, 0 5px 12px rgba(0,0,0,0.4);
    cursor: pointer;
    transition: transform 0.08s, box-shadow 0.08s;
    width: 100%;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b8860b; }
.btn.primary { background: linear-gradient(180deg, #078933, #078930); color: #fff; box-shadow: 0 3px 0 #045a21, 0 5px 12px rgba(0,0,0,0.4); }
.btn.big { min-height: 58px; font-size: 18px; }
.btn.owned { background: #2d6550; color: #cfeeda; box-shadow: none; cursor: default; }
.btn.buy.disabled { background: #54412f; color: #b49a77; box-shadow: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.icon-btn {
    min-width: 44px; min-height: 44px;
    border-radius: 12px;
    border: 1px solid #d4af37;
    background: rgba(44, 24, 16, 0.85);
    color: #ffd94a;
    font-size: 18px;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.back-btn {
    position: absolute;
    top: 16px; left: 16px;
    z-index: 5;
    background: rgba(44,24,16,0.9);
    color: #ffd94a;
    border: 1px solid #d4af37;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

/* ================================================================== */
/* MENU / SCREENS                                                      */
/* ================================================================== */
.menu {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 54px 16px 20px;
    overflow-y: auto;
    background: linear-gradient(180deg, rgba(44,24,16,0.97), rgba(26,15,8,0.98));
}
.screen-title {
    font-size: 22px;
    color: #ffd94a;
    text-align: center;
    margin-top: 6px;
    text-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

/* Title screen */
.title-block { text-align: center; margin-bottom: 8px; }
.eyebrow { font-size: 12px; letter-spacing: 2px; color: #e0b96a; text-transform: uppercase; }
.game-title {
    font-size: 34px;
    line-height: 1.1;
    color: #ffd94a;
    text-shadow: 0 3px 0 #8a5300, 0 6px 14px rgba(0,0,0,0.6);
    margin-top: 6px;
}
.subtitle { font-size: 16px; color: #ffe9b0; margin-top: 4px; font-style: italic; }

.menu-card {
    background: linear-gradient(180deg, rgba(120,68,32,0.55), rgba(60,30,14,0.85));
    border: 2px solid #d4af37;
    border-radius: 18px;
    padding: 18px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: inset 0 0 0 3px rgba(245,184,0,0.18), 0 8px 22px rgba(0,0,0,0.5);
}
.menu-actions { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 4px; }
.coin-pill {
    background: rgba(26,15,8,0.8);
    border: 1px solid #f5b800;
    color: #ffd94a;
    border-radius: 999px;
    padding: 8px 14px;
    font-weight: 800;
    font-size: 14px;
}
.menu-stars { display: flex; gap: 8px; justify-content: center; margin-bottom: 4px; }
.region-dot {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: #3a2a1a;
    color: #7a6450;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 13px;
    border: 2px solid #4a3420;
}
.region-dot.on { background: #078930; color: #fff; border-color: #ffd94a; }
.credits { font-size: 11px; color: #b08a5a; text-align: center; }

/* ================================================================== */
/* LEVEL SELECT                                                        */
/* ================================================================== */
.level-grid { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 380px; }
.level-card {
    background: linear-gradient(180deg, rgba(120,68,32,0.5), rgba(44,24,16,0.92));
    border: 2px solid #d4af37;
    border-radius: 14px;
    overflow: hidden;
}
.level-head { padding: 10px 14px; color: #fff; }
.level-region { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.95; }
.level-name { display: block; font-size: 18px; font-weight: 800; margin-top: 2px; text-shadow: 0 1px 3px rgba(0,0,0,0.5); }
.sub-levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 10px; }
.sub-level {
    min-height: 74px;
    border-radius: 12px;
    border: 2px solid rgba(255,255,255,0.25);
    background: rgba(240,220,190,0.1);
    color: #ffe9b0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    transition: transform 0.08s, background 0.2s;
    position: relative;
}
.sub-level:active { transform: scale(0.95); }
.sub-level.locked { cursor: not-allowed; filter: grayscale(1); opacity: 0.5; }
.sub-num { font-size: 22px; font-weight: 900; }
.sub-stars { font-size: 12px; color: #f5b800; letter-spacing: 1px; }
.sub-stars .s.on { color: #ffd94a; }
.sub-meta { font-size: 9px; color: #b89a72; }

/* ================================================================== */
/* ENCYCLOPEDIA                                                        */
/* ================================================================== */
.cat-tabs { display: flex; gap: 8px; width: 100%; max-width: 380px; }
.cat-tab {
    flex: 1;
    min-height: 42px;
    border-radius: 10px;
    border: 2px solid #d4af37;
    background: rgba(44,24,16,0.8);
    color: #e0b96a;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
}
.cat-tab.on { background: #078930; color: #fff; border-color: #ffd94a; }
.food-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 380px; }
.food-card {
    background: linear-gradient(180deg, rgba(120,68,32,0.55), rgba(44,24,16,0.9));
    border: 2px solid rgba(212,175,55,0.6);
    border-radius: 12px;
    padding: 12px;
    color: #fff;
    cursor: pointer;
    text-align: left;
    min-height: 84px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.food-name { font-size: 15px; font-weight: 800; color: #ffd94a; }
.food-desc { font-size: 11px; color: #d9b98a; line-height: 1.3; }

.modal {
    position: absolute;
    inset: 0;
    background: rgba(15,8,4,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}
.modal-card {
    background: linear-gradient(180deg, #6a3d1d, #3a2416);
    border: 3px solid #d4af37;
    border-radius: 18px;
    padding: 20px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    color: #fff;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 12px 30px rgba(0,0,0,0.6);
}
.modal-card h3 { color: #ffd94a; font-size: 22px; }
.m-desc { font-size: 14px; color: #ffe9b0; }
.m-story { font-size: 12px; color: #d9b98a; font-style: italic; line-height: 1.4; }
.m-ingredients { background: rgba(26,15,8,0.6); border-radius: 10px; padding: 12px; }
.m-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #ffd94a; margin-bottom: 6px; }
.ing { font-size: 13px; color: #ffe9c0; line-height: 1.6; }

/* ================================================================== */
/* SHOP                                                               */
/* ================================================================== */
.coin-banner {
    background: rgba(26,15,8,0.8);
    border: 1px solid #f5b800;
    color: #ffd94a;
    border-radius: 999px;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 800;
}
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 380px; padding-bottom: 20px; }
.shop-card {
    background: linear-gradient(180deg, rgba(120,68,32,0.55), rgba(44,24,16,0.9));
    border: 2px solid rgba(212,175,55,0.6);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    text-align: center;
}
.shop-icon { font-size: 26px; }
.shop-name { font-size: 14px; font-weight: 800; color: #ffd94a; }
.shop-desc { font-size: 11px; color: #d9b98a; line-height: 1.3; }

/* ================================================================== */
/* PAUSE / SUMMARY (modal)                                             */
/* ================================================================== */
.modal {
    position: absolute;
    inset: 0;
    background: rgba(15,8,4,0.72);
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
    text-align: center;
    color: #fff;
}
.overlay.dim > .modal { position: static; background: none; box-shadow: none; padding: 14px; }
.overlay.dim > .modal.summary {
    background: rgba(44,24,16,0.94);
    border: 2px solid #d4af37;
    border-radius: 18px;
    max-width: 360px;
    width: 100%;
    padding: 22px;
}
.modal h2 { color: #ffd94a; font-size: 26px; }
.stars-row { display: flex; justify-content: center; gap: 6px; font-size: 40px; }
.big-star { color: #4a4030; }
.big-star.on { color: #ffd94a; text-shadow: 0 0 12px rgba(245,184,0,0.7); }
.stat-line { font-size: 15px; color: #ffe9b0; margin: 3px 0; }
.stat-line .gold { color: #ffd94a; }
.stat-line b { color: #fff; }
.dim2 { color: #b89a72; }
.summary-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; width: 100%; }

/* scrollbars subtle */
.menu::-webkit-scrollbar { width: 6px; }
.menu::-webkit-scrollbar-thumb { background: #6a4a2a; border-radius: 6px; }

/* ---------------- OPEN ORDERS TICKET RAIL ---------------- */
.ticket-rail {
    position: absolute;
    top: 44px;
    left: 0; right: 0;
    max-height: 74px;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-direction: row;
    gap: 5px;
    pointer-events: auto;
    z-index: 120;
    padding: 2px 6px;
}
.ticket-card {
    background: #fff8e7;
    border: 2px solid #d4af37;
    border-left: 5px solid #078930;
    border-radius: 8px;
    padding: 3px 6px;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    font-family: inherit;
    transition: transform 0.12s ease;
    flex: 0 0 auto;
    min-width: 82px;
    max-width: 96px;
}
.ticket-card:active { transform: scale(0.96); }
.ticket-card.warn { border-left-color: #f5b800; }
.ticket-card.urgent { border-left-color: #da121a; animation: ticket-pulse 0.9s infinite; }
@keyframes ticket-pulse {
    0%, 100% { box-shadow: 0 2px 6px rgba(0,0,0,0.35); }
    50% { box-shadow: 0 0 10px rgba(218,18,26,0.8); }
}
.ticket-head { display: flex; justify-content: space-between; align-items: center; }
.ticket-seat { font-size: 8px; font-weight: 700; color: #8b4513; text-transform: uppercase; letter-spacing: 0.3px; }
.ticket-avatar { font-size: 12px; }
.ticket-items { display: flex; flex-direction: column; gap: 0px; margin: 2px 0; }
.ticket-main { font-size: 11px; font-weight: 800; color: #2c1810; line-height: 1.1; }
.ticket-side { font-size: 9px; color: #5a4632; line-height: 1.1; }
.ticket-patience { height: 4px; background: #e5d5b8; border-radius: 2px; overflow: hidden; }
.ticket-patience-fill { height: 100%; background: linear-gradient(90deg, #da121a, #f5b800, #078930); border-radius: 2px; transition: width 0.4s linear; }
.ticket-serve { margin-top: 2px; font-size: 8px; font-weight: 700; color: #078930; text-transform: uppercase; letter-spacing: 0.3px; text-align: center; }
.ticket-empty {
    font-size: 10px;
    color: #ffe9b0;
    background: rgba(44,24,16,0.7);
    border: 1px dashed #6a4a2a;
    border-radius: 6px;
    padding: 4px 10px;
    text-align: center;
    pointer-events: none;
}

/* ---------------- KITCHEN PREP BAR ---------------- */
.prep-bar {
    position: absolute;
    left: 50%;
    bottom: 4px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    pointer-events: none;
    z-index: 120;
    max-width: calc(100% - 10px);
}
.prep-stations { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.prep-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(44,24,16,0.88);
    border: 2px solid #6a4a2a;
    border-radius: 8px;
    padding: 2px 6px;
    min-width: 46px;
}
.prep-chip.cooking { border-color: #f5b800; }
.prep-chip.ready { border-color: #078930; background: rgba(7,80,30,0.9); animation: chip-glow 1s infinite; }
@keyframes chip-glow {
    0%, 100% { box-shadow: 0 0 4px rgba(7,137,48,0.5); }
    50% { box-shadow: 0 0 12px rgba(7,137,48,0.95); }
}
.prep-chip.idle { opacity: 0.65; }
.prep-name { font-size: 8px; font-weight: 700; color: #ffe9b0; line-height: 1.1; }
.prep-status { font-size: 7px; color: #ffd94a; font-weight: 700; line-height: 1.1; }
.prep-chip.ready .prep-status { color: #7dff9e; }
.prep-mesob {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(44,24,16,0.88);
    border: 2px solid #d4af37;
    border-radius: 10px;
    padding: 2px 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.prep-mesob-label { font-size: 9px; font-weight: 700; color: #ffd94a; }
.prep-mesob-empty { font-size: 9px; color: #b89a72; font-style: italic; }
.prep-mesob-item {
    font-size: 9px;
    font-weight: 700;
    color: #2c1810;
    background: #fff8e7;
    border-radius: 5px;
    padding: 1px 5px;
}

@media (max-width: 640px) {
    .ticket-card { min-width: 74px; max-width: 86px; }
    .prep-chip { min-width: 40px; padding: 2px 4px; }
}