:root {
  --text: #243447;
  --green: #40c057;
  --green-d: #2f9e44;
  --gold: #fcc419;
  --panel: rgba(255, 255, 255, 0.94);
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tile-w: 64px;
  --tile-h: 76px;
  --navy: #14253c;
  --navy-2: #1a2f4a;
}

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

html, body {
  height: 100%;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--text);
  background: #cfe8ff;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  max-width: 390px;
  width: 100%;
  margin: 0 auto;
  height: 100%;
  height: 100dvh;
  max-height: 844px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.18);
  /* Soft outdoor sky → grass — NEVER full template as bg */
  background: linear-gradient(180deg, #b8dcff 0%, #d5eef0 28%, #d8efc0 62%, #c5e090 100%);
}

/* ===== Screens: ONLY .active is visible ===== */
.screen {
  display: none !important;
  flex-direction: column;
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: absolute;
  inset: 0;
}
.screen.active {
  display: flex !important;
  position: relative;
}

/* ===== Home — cartoon cover (sky→grass, NOT mint essay-card) ===== */
#screen-home {
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  gap: 6px;
  padding: 12px 14px 10px;
  overflow-y: auto;
  background: transparent; /* inherit #app sky→grass */
}
.home-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin: 2px 0 0;
  z-index: 2;
}
.home-logo {
  width: min(318px, 92%);
  height: auto;
  display: block;
  margin: 0 auto -6px;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.28));
  pointer-events: none;
}
.home-ribbon {
  display: inline-block;
  position: relative;
  z-index: 3;
  background: linear-gradient(180deg, #ffe566 0%, #f0c014 100%);
  color: #3a2410;
  font-weight: 900;
  font-size: 0.98rem;
  letter-spacing: 0.14em;
  padding: 3px 18px 4px;
  border-radius: 12px;
  border: 3px solid #2c2416;
  box-shadow: 0 3px 0 #c49212, 0 6px 12px rgba(0, 0, 0, 0.18);
  margin-bottom: 2px;
}
.home-char {
  width: min(228px, 64%);
  height: auto;
  margin-top: -8px;
  margin-bottom: -2px;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.32));
  pointer-events: none;
  background: none;
  border: none;
  /* no white rectangle matte */
}
.home-tagline {
  font-size: 0.9rem;
  font-weight: 800;
  color: #1e3a5f;
  line-height: 1.35;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
  margin: 0 8px 2px;
  max-width: 320px;
}
.home-actions-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 300px;
  justify-content: center;
}
.home-actions-row .btn {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  font-size: 0.88rem;
}
.home-foot {
  font-size: 0.66rem;
  color: #4d6b58;
  margin-top: 2px;
  margin-bottom: 8px;
}

.btn {
  border: none;
  border-radius: 28px;
  padding: 13px 34px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(180deg, #69db7c, #2b8a3e);
  color: #fff;
  min-width: 240px;
  padding: 13px 36px;
  font-size: 1.12rem;
  border: 2.5px solid #fff;
  box-shadow: 0 4px 0 #237032, 0 8px 16px rgba(43, 138, 62, 0.35);
}
.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 2px solid #adb5bd;
}
.btn-danger {
  background: linear-gradient(180deg, #ff8787, #e03131);
  color: #fff;
  border: 2px solid #fff;
}
.level-list {
  width: 100%;
  max-width: 330px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 6px;
}
.level-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.88);
  border: 2px solid #fff;
  border-radius: 12px;
  padding: 7px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  color: var(--text);
}
.level-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.level-btn .stars { color: var(--gold); font-size: 0.85rem; }

/* ===== Game — compact, asset chrome, no pastel cards ===== */
#screen-game {
  padding: 0;
  background: transparent;
}
#screen-game.screen.active {
  display: flex !important;
  flex-direction: column;
}

.game-title-bar {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 4px 40px 0 8px;
  min-height: 38px;
  z-index: 6;
}
.gt-logo {
  height: 34px;
  width: auto;
  max-width: 70%;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}
.btn-mini {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: linear-gradient(180deg, #ff8787, #e03131);
  color: #fff;
  font-weight: 900;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(200, 40, 40, 0.35);
  z-index: 7;
}

/* Stage: character | speech | HUD — NO white card wrapper */
.stage {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 148px 1fr 118px;
  gap: 4px;
  align-items: end;
  margin: 0 6px 2px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  min-height: 124px;
  max-height: 140px;
  z-index: 5;
  overflow: visible;
}
.char-podium {
  flex: 0 0 auto;
  background: transparent;
  border-radius: 0;
  padding: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
}
.char-podium img {
  width: 138px;
  height: auto;
  max-height: 140px;
  object-fit: contain;
  object-position: bottom center;
  display: block;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.28));
}
.speech {
  background: #fff url('../assets/ui/speech-bubble.png') center / 100% 100% no-repeat;
  background-color: #fff;
  border-radius: 14px;
  padding: 8px 10px 10px;
  font-size: 0.66rem;
  line-height: 1.35;
  border: 2.5px solid #2c3e50;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
  align-self: center;
  font-weight: 600;
  position: relative;
  min-height: 78px;
  max-width: 100%;
}
.speech-lead { font-weight: 800; color: #1e3a5f; margin-bottom: 2px; }
.speech-list { list-style: none; }
.speech-list li {
  position: relative;
  padding-left: 11px;
  margin: 1px 0;
  font-weight: 700;
  color: #243447;
}
.speech-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: #1c7ed6;
  font-weight: 900;
}

.hud-meta {
  background:
    url('../assets/ui/hud-panel.png') center / 100% 100% no-repeat,
    linear-gradient(165deg, #1a2f4a, #0f2038);
  color: #fff;
  border-radius: 12px;
  padding: 8px 9px;
  min-width: 0;
  border: 2px solid #3b5b7e;
  font-size: 0.68rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  align-self: center;
}
.hud-meta .lv { font-weight: 900; font-size: 0.92rem; }
.hud-meta .chapter {
  display: inline-block;
  margin: 4px 0 6px;
  background: #f1f3f5;
  color: #1a2f4a;
  font-weight: 800;
  font-size: 0.62rem;
  padding: 2px 7px;
  border-radius: 6px;
}
.hud-meta .griev { color: #ffc9c9; font-weight: 700; }
.hud-meta .g-pct { color: #ff6b6b; font-size: 1.05rem; font-weight: 900; }
.hud-meta .g-face { margin: 0 2px; }
.hud-meta .goal { color: #a5d8ff; font-size: 0.58rem; margin-top: 4px; font-weight: 700; }

.freeze-badge {
  display: none;
  align-self: center;
  background: #74c0fc;
  color: #1864ab;
  font-weight: 800;
  font-size: 0.72rem;
  padding: 2px 10px;
  border-radius: 999px;
  margin: 0 auto 2px;
}
.freeze-badge.on,
.freeze-badge.show { display: inline-block; }

/* Mid row: thermo | board | tools — tight */
.play-row {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 62px 1fr 70px;
  gap: 4px;
  padding: 0 5px;
  z-index: 2;
}

/* Thermometer — art visible; thin live marker ONLY inside track */
.thermo-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: transparent;
  border-radius: 0;
  border: none;
  padding: 0;
  box-shadow: none;
  overflow: hidden;
  min-height: 0;
}
.thermo-inner {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.thermo-art {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: fill;
  object-position: top center;
  pointer-events: none;
  user-select: none;
}
.thermo-track {
  position: absolute;
  /* Align over thermometer tube only — clip so marker never floats outside */
  left: 12%;
  width: 34%;
  top: 18%;
  bottom: 12%;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}
.thermo-marker {
  position: absolute;
  left: 50%;
  transform: translate(-50%, 50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff8787, #c92a2a 70%);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  z-index: 3;
  transition: bottom 0.3s ease;
  pointer-events: none;
  font-size: 0; /* no emoji text — thin overlay only */
  line-height: 0;
  overflow: hidden;
}
.thermo-live,
.thermo,
.thermo-glass,
.thermo-fill,
.thermo-bulb {
  display: none !important;
}

/* Board on stone patio — no mint void, no pastel card */
.board-wrap {
  position: relative;
  min-height: 0;
  background:
    url('../assets/ui/board-panel.png') center / cover no-repeat,
    #c4b5b0;
  border: 3px solid rgba(255,255,255,0.55);
  border-radius: 14px;
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.15), 0 4px 12px rgba(0,0,0,0.18);
  overflow: hidden;
}
#board {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

/* Tiles 64×76 full-bleed PNG; labels hidden */
.tile {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 12px;
  cursor: pointer;
  background: transparent;
  border: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  transition: transform 0.1s, filter 0.15s;
  z-index: 1;
}
.tile.clickable { cursor: pointer; filter: brightness(1.03); }
.tile.clickable:active { transform: scale(0.94); }
.tile.blocked {
  filter: brightness(0.52) saturate(0.65);
  cursor: default;
  pointer-events: none;
}
.tile.hint-glow { outline: 3px solid #ffd43b; outline-offset: 1px; }
.tile img,
.tile img.tile-face,
.tile img.full-card {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  border-radius: 10px;
}
.tile .label,
.tile .tile-label { display: none !important; }

/* Tools — dark navy column, circular PNGs + red badges */
.tools-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px 2px 6px;
  background: linear-gradient(180deg, rgba(18, 34, 56, 0.94), rgba(12, 24, 42, 0.96));
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 4px 12px rgba(0,0,0,0.28);
}
.tools-col::-webkit-scrollbar { display: none; }
.tools-label {
  color: #a5d8ff;
  font-size: 0.52rem;
  font-weight: 800;
  text-align: center;
  margin: 1px 0;
  width: 100%;
}
.tools-label.special {
  color: #ffc9c9;
  margin-top: 3px;
}
.tool-btn {
  position: relative;
  width: 56px;
  border: none;
  background: transparent;
  border-radius: 12px;
  padding: 1px 1px 2px;
  cursor: pointer;
  color: #fff;
  font-family: inherit;
}
.tool-btn:disabled { opacity: 0.38; cursor: not-allowed; }
.tool-btn img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 50%;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}
.tool-btn.special img {
  width: 34px;
  height: 34px;
}
.tool-btn .tname {
  font-size: 0.48rem;
  font-weight: 800;
  text-align: center;
  margin-top: 1px;
  line-height: 1.1;
  color: #e7f5ff;
}
.tool-btn .tdesc {
  font-size: 0.36rem;
  opacity: 0.72;
  text-align: center;
  line-height: 1.1;
  color: #a5d8ff;
  display: none;
}
.tool-btn .badge {
  position: absolute;
  top: -1px;
  right: 2px;
  background: #fa5252;
  color: #fff;
  font-size: 0.55rem;
  font-weight: 900;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  z-index: 2;
}

/* Stash 3 slots */
.stash-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 3px 8px 1px;
  min-height: 30px;
}
.stash-slot {
  width: 40px;
  height: 48px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.28);
  border: 1.5px dashed rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.stash-slot.empty { opacity: 0.8; }
.stash-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
}

/* Tray + crowd */
.tray-section {
  flex: 0 0 auto;
  padding: 1px 6px calc(2px + var(--safe-bottom));
  z-index: 4;
}
.tray,
.tray-chrome {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  /* left ~22% is "7格處理槽" label in art */
  padding: 8px 9px 8px 22%;
  min-height: 62px;
  height: 68px;
  background-color: transparent;
  background-image: url('../assets/ui/tray-wood.png');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  border: none;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.22);
}
.tray-slot {
  aspect-ratio: 64 / 76;
  max-height: 50px;
  background: transparent;
  border-radius: 8px;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.tray-slot.filled { background: transparent; }
.tray-slot img,
.tray-slot img.tray-face {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
  pointer-events: none;
}
.tray-slot .label,
.tray-slot .tlab { display: none !important; }

.crowd-wrap {
  margin-top: 2px;
  margin-left: -6px;
  margin-right: -6px;
}
.crowd-bar {
  width: 100%;
  height: 64px;
  object-fit: cover;
  object-position: center bottom;
  border-radius: 0;
  display: block;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.12);
}

/* Modal / toast */
.modal-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal,
.modal-card {
  background: #fff;
  border-radius: 18px;
  padding: 20px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.modal h2,
.modal-card h2 { margin-bottom: 8px; }
.modal p,
.modal-card p { font-size: 0.9rem; margin-bottom: 14px; line-height: 1.4; }
.modal-actions,
.btn-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.stars-big {
  font-size: 1.8rem;
  color: var(--gold);
  margin: 6px 0 10px;
  letter-spacing: 2px;
}
.toast {
  position: absolute;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(33, 37, 41, 0.9);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 120;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal.win h2 { color: #2f9e44; }
.modal.fail h2 { color: #e03131; }

@media (max-height: 720px) {
  .char-podium img { width: 112px; max-height: 116px; }
  .stage { min-height: 100px; max-height: 118px; grid-template-columns: 116px 1fr 108px; }
  .crowd-bar { height: 48px; }
  .tray, .tray-chrome { height: 58px; min-height: 54px; padding-top: 6px; padding-bottom: 6px; }
  .play-row { grid-template-columns: 50px 1fr 62px; }
  .tool-btn img { width: 34px; height: 34px; }
  .tool-btn.special img { width: 30px; height: 30px; }
}

@media (max-height: 640px) {
  .crowd-bar { height: 40px; }
  .gt-logo { height: 26px; }
  .thermo-track { top: 14%; bottom: 16%; }
  .stage { min-height: 88px; max-height: 100px; }
  .char-podium img { width: 96px; max-height: 100px; }
}

/* Hard rules */
body, #app, .screen, #screen-game {
  background-image: none;
}
#app {
  background: linear-gradient(180deg, #b8dcff 0%, #d5eef0 28%, #d8efc0 62%, #c5e090 100%);
}
#screen-game {
  background: transparent;
}
body { background: #cfe8ff; }


/* crisp pixel-ish UI arts */
.thermo-art, .board-wrap {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}
.thermo-art {
  width: 100% !important;
  height: auto !important;
  max-height: 100%;
  object-fit: contain;
  object-position: center top;
  filter: none !important;
  opacity: 1 !important;
}
.board-wrap {
  background-size: cover !important;
  background-position: center !important;
}
