/* ==========================================================================
   HANZI FIRE BRIGADE (漢字消防員) — Responsive Tablet & Desktop Stylesheet
   File: css/style.css
   ========================================================================== */

:root {
  --bg-dark: #0f172a;
  --panel-bg: rgba(15, 23, 42, 0.88);
  --fire-red: #ef4444;
  --fire-orange: #f97316;
  --fire-gold: #facc15;
  --water-cyan: #38bdf8;
  --water-blue: #0284c7;
  --safe-green: #10b981;
  --text-light: #f8fafc;
  --text-muted: #cbd5e1;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-light);
  font-family: "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
}

/* Fullscreen 3D Corridor Canvas Layer */
#corridorCanvas {
  position: fixed;
   inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  display: block;
}

/* Main UI Overlay Grid */
.ui-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 18px;
  pointer-events: none;
}

.ui-overlay > * {
  pointer-events: auto;
}

/* Top Firefighter Helmet HUD Bar */
.hud-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.92), rgba(30, 41, 59, 0.92));
  border: 2px solid rgba(250, 204, 21, 0.55);
  border-radius: 16px;
  padding: 10px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.helmet-icon {
  font-size: 1.9rem;
  filter: drop-shadow(0 2px 6px rgba(250, 204, 21, 0.6));
}

.hud-titles h1 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--fire-gold);
  letter-spacing: 0.5px;
}

.hud-subbadges {
  display: flex;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge-pill {
  background: rgba(51, 65, 85, 0.85);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

/* HUD Status Gauges (Lives, Timer, Score) */
.hud-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.hud-lives {
  display: flex;
  gap: 4px;
  font-size: 1.35rem;
}

.hud-timer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 170px;
}

.timer-track {
  flex: 1;
  height: 14px;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 999px;
  border: 1.5px solid rgba(148, 163, 184, 0.45);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background-color: #22c55e;
  transition: width 0.1s linear, background-color 0.25s ease;
}

.timer-label {
  font-weight: 800;
  font-size: 0.98rem;
  min-width: 36px;
  text-align: right;
  color: #fde047;
}

.hud-score-box {
  background: rgba(2, 132, 199, 0.25);
  border: 1.5px solid var(--water-cyan);
  border-radius: 12px;
  padding: 4px 12px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #e0f2fe;
}

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

.hud-btn {
  background: rgba(30, 41, 59, 0.92);
  color: var(--text-light);
  border: 1.5px solid rgba(148, 163, 184, 0.45);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.hud-btn:hover, .hud-btn:active {
  transform: translateY(-1px);
  background: rgba(51, 65, 85, 0.95);
  border-color: var(--water-cyan);
}

.hud-btn.active-toggle {
  background: rgba(2, 132, 199, 0.35);
  border-color: var(--water-cyan);
  color: #bae6fd;
}

/* Encouraging Bilingual Feedback Banner */
.feedback-banner {
  align-self: center;
  margin-top: 6px;
  padding: 8px 20px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.88);
  border: 2px solid var(--water-cyan);
  text-align: center;
  max-width: 92vw;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.feedback-banner.mood-success {
  border-color: #4ade80;
  background: rgba(6, 78, 59, 0.9);
}

.feedback-banner.mood-warning {
  border-color: #fb923c;
  background: rgba(124, 45, 18, 0.9);
}

.feedback-zh {
  font-size: 1.05rem;
  font-weight: 800;
  color: #ffffff;
}

.feedback-en {
  font-size: 0.82rem;
  color: #bae6fd;
  margin-top: 1px;
}

/* Center-Bottom Interactive Area (Writing Pad & 3D Corridor Navigation) */
.center-stage {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  gap: 16px;
  margin-top: auto;
  padding-bottom: 4px;
}

/* Water-Stream Calligraphy Writing Panel */
.writing-panel {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel-bg);
  border: 2.5px solid var(--water-cyan);
  border-radius: 20px;
  padding: 12px 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
}

.char-info-column {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 225px;
}

.char-header-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.target-char-big {
  font-size: 2.6rem;
  font-weight: 900;
  color: var(--fire-gold);
  line-height: 1;
}

.target-phonetics {
  display: flex;
  flex-direction: column;
}

.target-pinyin {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--water-cyan);
}

.target-meaning {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.sequence-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.seq-pill {
  padding: 2px 9px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.9rem;
  background: #334155;
  color: #94a3b8;
}

.seq-pill.active {
  background: var(--fire-orange);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(249, 115, 22, 0.6);
}

.seq-pill.done {
  background: var(--safe-green);
  color: #ffffff;
}

.stroke-meta-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: #e2e8f0;
}

.stroke-rule-box {
  font-size: 0.78rem;
  color: #fde047;
  background: rgba(250, 204, 21, 0.12);
  border-left: 3px solid var(--fire-gold);
  padding: 5px 8px;
  border-radius: 6px;
  line-height: 1.35;
}

.pad-controls-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.canvas-wrapper {
  position: relative;
  width: 240px;
  height: 240px;
  flex: 0 0 auto; /* never flex-shrink: the 米字格 pad must stay square */
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid rgba(56, 189, 248, 0.65);
  box-shadow: inset 0 0 18px rgba(2, 132, 199, 0.35);
  touch-action: none;
}

#strokeCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* First-Person 3D Corridor Movement Panel (Unlocked after extinguishing fire!) */
.movement-panel {
  margin: 0 auto;
  background: linear-gradient(135deg, rgba(6, 78, 59, 0.94), rgba(15, 23, 42, 0.95));
  border: 3px solid #34d399;
  border-radius: 22px;
  padding: 16px 24px;
  text-align: center;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.65);
  animation: popIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.movement-panel h3 {
  font-size: 1.15rem;
  color: #a7f3d0;
  margin-bottom: 4px;
}

.movement-panel p {
  font-size: 0.85rem;
  color: #d1fae5;
  margin-bottom: 12px;
}

.move-buttons-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.move-btn {
  min-width: 135px;
  padding: 14px 18px;
  border-radius: 14px;
  border: 2px solid #6ee7b7;
  background: linear-gradient(180deg, #10b981, #059669);
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.move-btn:hover, .move-btn:active {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 8px 22px rgba(52, 211, 153, 0.65);
}

/* Modals (Level Summary, Level Select, 15-Char Curriculum) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(2, 6, 23, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  border: 2.5px solid var(--water-cyan);
  border-radius: 22px;
  padding: 24px;
  max-width: 720px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  color: var(--text-light);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-size: 1.4rem;
  color: var(--fire-gold);
}

.summary-stars {
  font-size: 2.6rem;
  text-align: center;
  margin: 10px 0 16px;
}

.summary-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-box {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.metric-box .label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.metric-box .value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--water-cyan);
  margin-top: 4px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.level-card {
  background: rgba(30, 41, 59, 0.9);
  border: 2px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
  padding: 12px;
  text-align: left;
  color: var(--text-light);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.level-card:hover, .level-card.active-level {
  transform: translateY(-2px);
  border-color: var(--fire-gold);
}

.level-card-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  margin-bottom: 6px;
}

.level-tier-tag {
  background: rgba(2, 132, 199, 0.35);
  color: #7dd3fc;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 700;
}

.level-card h4 {
  font-size: 0.98rem;
  color: #fde047;
  margin-bottom: 4px;
}

.level-chars-preview {
  font-size: 0.92rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 4px;
}

.level-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Curriculum Table */
.curriculum-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.curriculum-table th, .curriculum-table td {
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  padding: 8px 6px;
  text-align: left;
}

.curriculum-table th {
  color: var(--fire-gold);
  font-weight: 800;
}

.curriculum-table .char-cell {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--water-cyan);
}

.hidden {
  display: none !important;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Tablet & Mobile Responsive Breakpoints */
@media (max-width: 768px) {
  .writing-panel {
    flex-direction: column;
    align-items: center;
    padding: 10px 12px;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
  }
  .char-info-column {
    max-width: 100%;
    text-align: center;
    align-items: center;
  }
  .canvas-wrapper {
    width: min(210px, 32vh, 58vw);
    height: auto;
  }
}

/* ==========================================================================
   Phone & short-viewport fit — the whole mission UI (HUD · feedback banner ·
   米字格 pad) must stay usable without scrolling on a phone in either
   orientation. The pad is clamped by viewport height so it can never be
   pushed off screen; the HUD compacts instead.
   ========================================================================== */

.canvas-wrapper {
  width: min(240px, 32vh, 58vw);
  width: min(240px, 32dvh, 58vw);
  height: auto; /* square comes from aspect-ratio, never a fixed height */
}

@media (max-width: 768px) {
  .ui-overlay { padding: 6px 8px; gap: 6px; }
  .hud-topbar { padding: 6px 8px; gap: 6px; border-radius: 12px; }
  .helmet-icon { font-size: 1.05rem; }
  .hud-titles h1 { font-size: 0.78rem; }
  .hud-subbadges { gap: 4px; font-size: 0.58rem; margin-top: 0; }
  .badge-pill { padding: 1px 6px; }
  .hud-stats { gap: 8px; font-size: 0.68rem; }
  .hud-actions { width: 100%; display: flex; gap: 4px; }
  .hud-actions .hud-btn { flex: 1 1 0; font-size: 0.56rem; padding: 4px 2px; text-align: center; line-height: 1.15; }
  .feedback-banner { padding: 4px 10px; margin-top: 2px; border-width: 1.5px; }
  .feedback-zh { font-size: 0.74rem; line-height: 1.2; }
  .feedback-en { font-size: 0.58rem; }
  .center-stage { gap: 8px; padding-bottom: 0; }
  .writing-panel { padding: 8px; gap: 8px; border-radius: 14px; border-width: 2px; }
  .char-info-column { gap: 3px; max-width: 190px; }
  .target-char-big { font-size: 1.7rem; }
  .target-pinyin { font-size: 0.85rem; }
  .target-meaning { font-size: 0.66rem; }
  .stroke-meta-text { font-size: 0.68rem; }
  .stroke-rule-box { font-size: 0.66rem; padding: 3px 6px; }
  .seq-pill { font-size: 0.72rem; padding: 1px 7px; }
  .pad-controls-row { gap: 4px; margin-top: 2px; }
  .pad-controls-row .hud-btn { font-size: 0.6rem; padding: 4px 8px; }
  .movement-panel { padding: 10px 12px; border-width: 2px; border-radius: 16px; }
  .movement-panel h3 { font-size: 0.8rem; }
  .movement-panel p { font-size: 0.64rem; margin-bottom: 6px; }
  .move-btn { min-width: 0; flex: 1 1 30%; font-size: 0.72rem; padding: 10px 6px; border-radius: 10px; }
  .modal-card { padding: 14px; max-height: 88vh; max-height: 88dvh; overflow-y: auto; }
  .curriculum-table { font-size: 0.62rem; }
}

@media (max-width: 400px) {
  .hud-actions .hud-btn { font-size: 0.5rem; padding: 3px 1px; }
  .hud-titles h1 { font-size: 0.7rem; }
  .feedback-zh { font-size: 0.68rem; }
  .writing-panel { padding: 6px; gap: 6px; }
  .target-char-big { font-size: 1.5rem; }
  .pad-controls-row .hud-btn { font-size: 0.55rem; padding: 3px 6px; }
  .move-btn { font-size: 0.64rem; padding: 8px 4px; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .ui-overlay { padding: 4px 6px; gap: 4px; }
  .hud-topbar { padding: 4px 6px; gap: 6px; }
  .hud-titles h1 { font-size: 0.7rem; }
  .hud-actions .hud-btn { font-size: 0.5rem; padding: 3px 2px; }
  .feedback-en { display: none; }
  .canvas-wrapper {
    width: min(210px, 52vh, 34vw);
    width: min(210px, 52dvh, 34vw);
    height: auto;
  }
  .ui-overlay { justify-content: flex-end; }
  .hud-topbar { flex-wrap: nowrap; }
  .hud-subbadges { display: none; }
  .writing-panel { flex-direction: row; align-items: center; }
  .char-info-column { flex: 1 1 auto; max-width: none; }
  .target-char-big { font-size: 1.5rem; }
  .char-info-column { gap: 2px; }
  .stroke-rule-box { font-size: 0.6rem; padding: 2px 5px; }
  .move-btn { font-size: 0.62rem; padding: 8px 4px; }
}

/* Small portrait phones (iPhone SE / 568px-tall and similar) */
@media (max-height: 620px) and (orientation: portrait) {
  /* the pad is disabled while choosing a corridor — hand its space to the
     direction panel so nothing is pushed off a 568px-tall screen */
  body.awaiting-move #writingPanel { display: none; }
  .hud-stats { flex-wrap: nowrap; gap: 6px; }
  .char-info-column { gap: 2px; }
  .stroke-meta-text { font-size: 0.64rem; }
  .stroke-rule-box { font-size: 0.6rem; padding: 2px 5px; }
  .canvas-wrapper {
    width: min(190px, 28vh, 50vw);
    width: min(190px, 28dvh, 50vw);
    height: auto;
  }
}
