:root {
  --yellow: #ffd93d;
  --yellow-dark: #f7b500;
  --cream: #fff9e3;
  --ink: #2b2118;
  --green: #5cb85c;
  --red: #e25555;
  --blue: #4ea0ff;
  --shadow: 0 4px 0 #d4a800, 0 8px 16px rgba(0,0,0,.18);
  --card: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; font-family: 'Trebuchet MS', system-ui, sans-serif; color: var(--ink); }
body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 10%, #fff0a8 0%, transparent 50%),
    radial-gradient(circle at 80% 30%, #ffe48a 0%, transparent 50%),
    linear-gradient(180deg, #fff5c2 0%, #ffd93d 100%);
}

.hud {
  display:flex; align-items:center; gap:16px; padding:10px 18px;
  background: linear-gradient(180deg, #fff 0%, #fff7d6 100%);
  border-bottom: 4px solid var(--yellow-dark);
  position: sticky; top:0; z-index: 10;
  flex-wrap: wrap;
}
.logo { font-size: 22px; font-weight: 800; letter-spacing: .5px; }
.hud-stats { display:flex; gap:14px; flex-wrap: wrap; flex: 1; }
.stat {
  background: var(--cream); border: 2px solid var(--yellow-dark);
  border-radius: 10px; padding: 6px 10px; min-width: 80px;
  display: flex; flex-direction: column; align-items: flex-start;
}
.stat .label { font-size: 10px; text-transform: uppercase; opacity:.7; }
.stat span:last-child { font-weight: 700; font-size: 15px; }

.hud-actions { display:flex; gap: 6px; flex-wrap: wrap; }

.btn {
  font-family: inherit; font-weight: 700;
  border: 2px solid var(--ink); border-radius: 10px;
  background: var(--yellow); color: var(--ink);
  padding: 8px 14px; cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .05s, box-shadow .05s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity:.5; cursor: not-allowed; }
.btn.primary { background: var(--green); color: #fff; border-color: #2f7a2f; box-shadow: 0 3px 0 #2f7a2f; }
.btn.warn { background: var(--red); color: #fff; border-color: #8b2a2a; box-shadow: 0 3px 0 #8b2a2a; }
.btn.ghost { background: #fff; }
.btn.big { font-size: 18px; padding: 14px 22px; width: 100%; margin-top: 10px; }
.btn.small { padding: 4px 8px; font-size: 12px; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1400px; margin: 0 auto;
}
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; gap: 12px; padding: 12px; } }

/* ---- Mobile (<=640px) ---- */
@media (max-width: 640px) {
  html, body { -webkit-text-size-adjust: 100%; }
  .hud {
    padding: 8px 10px; gap: 8px;
    flex-direction: column; align-items: stretch;
    position: static; /* avoid sticky eating screen space on small phones */
  }
  .logo { font-size: 18px; text-align: center; }
  .hud-stats { gap: 6px; justify-content: space-between; }
  .stat { min-width: 0; flex: 1 1 30%; padding: 4px 6px; }
  .stat .label { font-size: 9px; }
  .stat span:last-child { font-size: 13px; }
  .hud-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .hud-actions .btn { padding: 10px 6px; font-size: 12px; }

  .panel { padding: 12px; border-radius: 12px; }
  .panel h2 { font-size: 15px; }

  /* Sliders: bigger thumb / taller track for touch */
  input[type=range] { height: 36px; }
  input[type=range]::-webkit-slider-thumb { transform: scale(1.3); }

  .recipe label { font-size: 14px; }
  .recipe-stats { font-size: 14px; }
  .price-display { font-size: 26px; }

  .shop { font-size: 14px; }
  .shop th, .shop td { padding: 8px 4px; }
  .btn.small { padding: 8px 10px; font-size: 13px; min-height: 36px; }

  .stand { min-height: 120px; padding: 12px; }
  .stand-art { font-size: 40px; }
  .btn.big { font-size: 17px; padding: 16px 18px; }

  .modal {
    width: 96%;
    max-height: 88vh;
    padding: 14px 16px;
    border-radius: 12px;
  }
  .row { padding: 10px 0; gap: 8px; flex-wrap: wrap; }
  .row .info { min-width: 0; flex-basis: 100%; }
  .row > div:last-child { margin-left: auto; }

  #toast-container { left: 10px; right: 10px; bottom: 10px; align-items: stretch; }
  .toast { font-size: 13px; }
}

/* Minimum 40px tap target for all interactive buttons */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 40px; }
}

.panel {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 4px 0 10px; font-size: 16px; border-bottom: 2px dashed #ddd; padding-bottom: 4px; }

.recipe .slider-row { margin-bottom: 8px; }
.recipe label { display:flex; justify-content: space-between; font-weight: 600; font-size: 13px; }
.recipe input[type=range], .price input[type=range] { width: 100%; accent-color: var(--yellow-dark); }
.recipe-stats { display:flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.price-display { text-align:center; font-size: 22px; font-weight: 800; }
.margin-display { text-align:center; font-size: 12px; opacity:.8; }

.shop { width: 100%; border-collapse: collapse; font-size: 13px; }
.shop th, .shop td { padding: 6px 4px; text-align: left; border-bottom: 1px solid #eee; }
.shop th { background: var(--cream); }
.shop td:last-child, .shop th:last-child { text-align: right; }

.forecast { font-size: 13px; background: var(--cream); border-radius: 8px; padding: 8px; }

.center { display:flex; flex-direction: column; }
.stand { background: linear-gradient(180deg,#fff5c2,#ffd93d); border:2px dashed var(--ink); border-radius: 12px; padding: 16px; text-align:center; flex:1; min-height: 160px; display:flex; flex-direction:column; align-items:center; justify-content:center; gap: 8px;}
.stand-art { font-size: 48px; line-height: 1; }
.stand-info { font-size: 13px; font-weight: 600; min-height: 30px; }

.day-progress {
  display: none;
  margin-top: 12px;
  background: var(--cream);
  border: 2px solid var(--yellow-dark);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}
.day-progress.show { display: block; }
.day-progress-label { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.day-progress-track {
  width: 100%;
  height: 16px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 2px 0 rgba(0,0,0,.08);
}
.day-progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--yellow) 0%, var(--yellow-dark) 50%, var(--green) 100%);
  transition: width linear;
}
.day-progress-emoji {
  font-size: 28px;
  margin-top: 6px;
  display: inline-block;
  animation: wiggle 0.6s ease-in-out infinite alternate;
}
@keyframes wiggle {
  from { transform: translateY(0) rotate(-8deg); }
  to   { transform: translateY(-4px) rotate(8deg); }
}

.today-news { margin-top: 10px; }
.today-news .news { background: var(--cream); border: 2px dashed var(--yellow-dark); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.active-mkt, .active-staff { margin-top: 10px; font-size: 12px; }
.active-mkt .tag, .active-staff .tag { display:inline-block; padding: 3px 8px; margin: 2px; background: var(--cream); border: 1px solid var(--yellow-dark); border-radius: 999px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display:none; z-index: 50; }
.modal-backdrop.show { display:block; }
.modal { display:none; position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); background: #fff; padding: 18px 22px; border-radius: 16px; border: 3px solid var(--ink); box-shadow: var(--shadow); z-index: 60; max-width: 600px; width: 90%; max-height: 80vh; overflow-y: auto; }
.modal.show { display:block; }
.modal h2 { margin-top: 0; }

.row { display:flex; align-items:center; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed #eee; gap: 10px; }
.row:last-child { border-bottom: none; }
.row .meta { font-size: 12px; opacity:.75; }
.row .info { flex: 1; }
.row .info b { font-size: 14px; }

.summary-grid { display:grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-size: 14px; }
.summary-grid .total { font-weight: 800; border-top: 2px solid var(--ink); padding-top: 6px; margin-top: 4px; }

.summary-header { display: flex; justify-content: space-between; align-items: stretch; gap: 12px; margin-bottom: 8px; }
.summary-day { font-size: 22px; font-weight: 800; }
.summary-weather { font-size: 14px; opacity: .8; }
.summary-profit { text-align: right; padding: 6px 12px; border-radius: 10px; background: var(--cream); border: 2px solid var(--yellow-dark); min-width: 120px; }
.summary-profit .label { font-size: 11px; text-transform: uppercase; opacity:.7; }
.summary-profit .big { font-size: 22px; font-weight: 800; }
.summary-profit.pos { background: #d6f5d6; border-color: #2f7a2f; }
.summary-profit.pos .big { color: #2f7a2f; }
.summary-profit.neg { background: #fcd9d9; border-color: #8b2a2a; }
.summary-profit.neg .big { color: #8b2a2a; }
.summary-profit .streak { font-size: 11px; opacity:.8; }

.records-row { display:flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.record-badge { background: var(--yellow); border: 2px solid var(--ink); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; box-shadow: 0 2px 0 var(--ink); }

#modal-day-summary h3 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: #6b5e4a; border-bottom: 1px dashed #ddd; padding-bottom: 4px; }
.kv-grid { display:grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-size: 14px; }
.kv-grid .total { font-weight: 800; border-top: 2px solid var(--ink); padding-top: 6px; margin-top: 4px; }
.kv-grid .pos { color: #2f7a2f; font-weight: 700; }
.kv-grid .neg { color: #8b2a2a; }

.hourly-chart { display:flex; justify-content: space-between; align-items: flex-end; height: 70px; padding: 4px 0; }
.hour-col { display: flex; flex-direction: column; align-items: center; flex:1; }
.hour-stack { position: relative; width: 80%; height: 48px; display: flex; align-items: flex-end; justify-content: center; }
.hour-bar { width: 100%; border-radius: 3px 3px 0 0; }
.hour-bar.arrivals { background: rgba(255,193,80,.45); position: absolute; bottom: 0; left: 0; right: 0; }
.hour-bar.sold     { background: var(--yellow-dark); position: absolute; bottom: 0; left: 0; right: 0; }
.hour-label { font-size: 9px; opacity:.7; margin-top: 2px; }
.legend { font-size: 11px; opacity:.75; margin-top: 4px; text-align: center; }
.legend .dot { display:inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 2px; }
.legend .dot.arrivals { background: rgba(255,193,80,.45); }
.legend .dot.sold     { background: var(--yellow-dark); }

.walks { display:flex; flex-direction: column; gap: 4px; }
.walk-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 8px; background: var(--cream); border-radius: 6px; }

.feedback { font-size: 13px; margin: 4px 0; padding-left: 20px; }
.feedback li { margin: 2px 0; }

.trends { margin-top: 10px; }
.trend-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.trend-label { font-size: 12px; min-width: 160px; opacity: .8; }
.spark { display:flex; align-items: flex-end; gap: 2px; height: 30px; flex:1; }
.spark-bar { width: 8px; border-radius: 2px; }
.spark-bar.pos  { background: var(--green); }
.spark-bar.neg  { background: var(--red); }
.spark-bar.zero { background: #ccc; }

#toast-container { position: fixed; bottom: 20px; right: 20px; display:flex; flex-direction: column; gap: 6px; z-index: 80; }
.toast { background: var(--ink); color: var(--yellow); padding: 10px 14px; border-radius: 10px; font-weight: 700; box-shadow: 0 4px 12px rgba(0,0,0,.3); animation: pop .3s ease; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.achievement { display:flex; align-items:center; gap: 10px; padding: 6px 0; }
.achievement.locked { opacity:.4; }
.achievement .icon { font-size: 22px; }

.pill { display:inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--cream); border:1px solid var(--yellow-dark); }
.pill.ok { background: #d6f5d6; border-color: #2f7a2f; color: #2f7a2f; }
.pill.bad { background: #fcd9d9; border-color: #8b2a2a; color: #8b2a2a; }
