/* ============================================================
   皇城信使 The Imperial Messenger — UI stylesheet
   Chinese-first bilingual UI. Rice-paper panels, lacquer buttons.
   ============================================================ */

:root {
  --font-zh: "KaiTi", "STKaiti", "DFKai-SB", "BiauKai", "Microsoft YaHei", "Noto Sans SC", serif;
  --font-en: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  --lacquer: #a4232a;
  --lacquer-dark: #7c151b;
  --gold: #e8b93c;
  --gold-dark: #a06818;
  --ink: #2b2018;
  --paper: #f4e8cd;
  --paper-dark: #e5d3ac;
  --jade: #3f9e6e;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #10131c;
  font-family: var(--font-en);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#game-root { position: fixed; inset: 0; }

#game {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  image-rendering: auto;
}

.hidden { display: none !important; }

/* ---------- bilingual text helpers ---------- */
.zh { font-family: var(--font-zh); display: block; }
.en { font-family: var(--font-en); display: block; opacity: 0.82; }

/* ============================================================
   HUD
   ============================================================ */
#hud {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 10;
}
#hud-left {
  position: absolute; top: 12px; left: 14px;
  display: flex; flex-direction: column; gap: 6px;
}
#hud-hearts { display: flex; gap: 4px; height: 26px; }
#hud-hearts img, #hud-hearts svg { width: 26px; height: 26px; }
.hud-heart { width: 26px; height: 26px; }
.hud-heart.empty { opacity: 0.28; filter: grayscale(1); }

#hud-healthbar {
  width: 226px; height: 22px;
  background: rgba(20, 14, 8, 0.72);
  border: 2px solid var(--gold-dark);
  border-radius: 11px;
  padding: 3px;
}
#hud-health-segs { display: flex; gap: 2px; height: 100%; }
.hseg {
  flex: 1; border-radius: 4px;
  background: linear-gradient(180deg, #ff7a5c 0%, #d92f1e 55%, #a01608 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45);
  transition: opacity 0.15s;
}
.hseg.off { background: #3a2f26; box-shadow: none; }

#hud-buffs { display: flex; gap: 6px; }
.buff-icon {
  width: 30px; height: 30px; border-radius: 8px;
  background: rgba(20,14,8,0.6); border: 2px solid var(--jade);
  display: flex; align-items: center; justify-content: center;
}
.buff-icon img { width: 22px; height: 22px; }

#hud-right {
  position: absolute; top: 12px; right: 14px;
  display: flex; align-items: center; gap: 12px;
}
#hud-coins {
  display: flex; align-items: center; gap: 8px;
  background: rgba(20, 14, 8, 0.72);
  border: 2px solid var(--gold-dark); border-radius: 20px;
  padding: 4px 14px 4px 6px;
}
#hud-coin-icon img { width: 26px; height: 26px; display: block; }
#hud-coin-count {
  color: var(--gold); font-size: 20px; font-weight: bold;
  font-family: var(--font-en); min-width: 34px; text-align: right;
  text-shadow: 0 1px 2px #000;
}
#hud-rod {
  width: 38px; height: 38px; border-radius: 10px;
  background: rgba(20,14,8,0.72); border: 2px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
}
#hud-rod img { width: 30px; height: 30px; transform: rotate(45deg); }

/* ============================================================
   Overlay panels (menus / shop / dialogs)
   ============================================================ */
#overlay {
  position: absolute; inset: 0;
  z-index: 20;
  pointer-events: none;
}
#overlay > * { pointer-events: auto; }

.panel-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  background: radial-gradient(ellipse at 50% 40%, rgba(30, 20, 14, 0.55), rgba(10, 8, 6, 0.86));
  animation: fadein 0.35s ease-out;
}
.panel-screen.transparent { background: rgba(10, 8, 6, 0.35); }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(26px); opacity: 0; } to { transform: none; opacity: 1; } }

.paper {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.25), rgba(0,0,0,0.05)),
    var(--paper);
  border: 4px solid var(--lacquer);
  outline: 2px solid var(--gold-dark);
  outline-offset: -8px;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
  padding: 26px 40px;
  color: var(--ink);
  text-align: center;
  max-width: min(680px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  animation: slideup 0.3s ease-out;
}

.title-zh {
  font-family: var(--font-zh);
  font-size: clamp(38px, 7vw, 64px);
  letter-spacing: 0.12em;
  color: var(--lacquer);
  text-shadow: 0 2px 0 rgba(0,0,0,0.12);
}
.title-en {
  font-family: var(--font-en);
  font-size: clamp(15px, 2.4vw, 22px);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: #6b5232;
  margin-top: 2px;
}

.sub-zh { font-family: var(--font-zh); font-size: clamp(20px, 3.4vw, 30px); }
.sub-en { font-family: var(--font-en); font-size: clamp(12px, 1.9vw, 16px); opacity: 0.75; }

/* bright-gold variant for text sitting on the dark menu backdrop */
.on-dark .sub-zh { color: var(--gold); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); }
.on-dark .sub-en { color: #dfc27e; opacity: 1; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7); }

.body-zh { font-family: var(--font-zh); font-size: clamp(18px, 3vw, 26px); line-height: 1.45; }
.body-en { font-family: var(--font-en); font-size: clamp(12px, 1.9vw, 16px); opacity: 0.78; line-height: 1.4; margin-top: 4px; }

/* ---------- buttons ---------- */
.btn-col { display: flex; flex-direction: column; gap: 12px; align-items: center; margin-top: 8px; }
.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }

.gbtn {
  cursor: pointer;
  min-width: 230px;
  border: 3px solid var(--gold-dark);
  border-radius: 12px;
  background: linear-gradient(180deg, #c93a41 0%, var(--lacquer) 45%, var(--lacquer-dark) 100%);
  color: #ffe9b8;
  padding: 9px 26px 11px;
  text-align: center;
  box-shadow: 0 4px 0 #55090e, 0 6px 14px rgba(0,0,0,0.45);
  transition: transform 0.06s, box-shadow 0.06s, filter 0.12s;
  font-size: 16px;
}
.gbtn .zh { font-size: 24px; letter-spacing: 0.2em; font-weight: bold; }
.gbtn .en { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; }
.gbtn:hover:not(:disabled) { filter: brightness(1.12); }
.gbtn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #55090e; }
.gbtn:disabled { cursor: default; filter: grayscale(0.8) brightness(0.75); }
.gbtn.gbtn-small { min-width: 140px; padding: 6px 16px 8px; }
.gbtn.gbtn-small .zh { font-size: 18px; }
.gbtn.gbtn-jade { background: linear-gradient(180deg, #4fbd85 0%, var(--jade) 45%, #2b7a52 100%); box-shadow: 0 4px 0 #17573a, 0 6px 14px rgba(0,0,0,0.45); }
.gbtn.gbtn-jade:active:not(:disabled) { box-shadow: 0 1px 0 #17573a; }

/* ---------- level select ---------- */
.level-grid { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.lvbtn {
  width: 64px; height: 64px; cursor: pointer;
  border: 3px solid var(--gold-dark); border-radius: 12px;
  background: linear-gradient(180deg, #c93a41, var(--lacquer-dark));
  color: #ffe9b8; font-family: var(--font-zh); font-size: 26px; font-weight: bold;
  box-shadow: 0 3px 0 #55090e;
  position: relative;
}
.lvbtn:hover:not(:disabled) { filter: brightness(1.15); }
.lvbtn:disabled { cursor: default; filter: grayscale(0.9) brightness(0.6); }
.lvbtn .lock { position: absolute; right: 4px; bottom: 2px; font-size: 15px; }

/* ---------- shop ---------- */
.shop-items { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.shop-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--paper-dark);
  border: 2px solid var(--gold-dark); border-radius: 10px;
  padding: 8px 12px; text-align: left;
}
.shop-item.sold { opacity: 0.5; }
.shop-item .icon {
  width: 52px; height: 52px; flex: 0 0 52px;
  background: rgba(255,255,255,0.45); border: 2px solid var(--gold-dark); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.shop-item .icon img { max-width: 40px; max-height: 40px; }
.shop-item .info { flex: 1; min-width: 0; }
.shop-item .info .zh { font-size: 21px; }
.shop-item .info .en { font-size: 12px; }
.shop-item .price {
  display: flex; align-items: center; gap: 5px;
  color: #7a5210; font-weight: bold; font-size: 18px; white-space: nowrap;
}
.shop-item .price img { width: 20px; height: 20px; }
.shop-buy { min-width: 92px !important; }
.coin-inline { width: 22px; height: 22px; vertical-align: -4px; }
.scroll-img { width: 96px; height: auto; }

/* ---------- dialog (speech box at bottom) ---------- */
.dialog-box {
  position: absolute; left: 50%; bottom: 6vh;
  transform: translateX(-50%);
  width: min(760px, 92vw);
  background: var(--paper);
  border: 4px solid var(--lacquer);
  outline: 2px solid var(--gold-dark); outline-offset: -8px;
  border-radius: 14px;
  padding: 16px 26px 14px;
  color: var(--ink);
  box-shadow: 0 12px 30px rgba(0,0,0,0.55);
  animation: slideup 0.25s ease-out;
}
.dialog-name { font-family: var(--font-zh); color: var(--lacquer); font-size: 20px; margin-bottom: 4px; }
.dialog-hint { text-align: right; font-size: 12px; opacity: 0.6; margin-top: 6px; font-family: var(--font-en); }

/* ---------- toast (small centered hint e.g. "Press E") ---------- */
#toast {
  position: absolute; left: 50%; bottom: 15vh; transform: translateX(-50%);
  background: rgba(20, 14, 8, 0.8);
  border: 2px solid var(--gold-dark); border-radius: 12px;
  color: #ffe9b8; padding: 8px 22px; text-align: center;
  z-index: 15; pointer-events: none;
  animation: fadein 0.2s ease-out;
}
#toast .zh { font-size: 22px; font-family: var(--font-zh); }
#toast .en { font-size: 12px; }

/* ---------- loading ---------- */
#loading-bar-wrap {
  width: min(420px, 70vw); height: 18px;
  border: 2px solid var(--gold-dark); border-radius: 9px;
  background: rgba(0,0,0,0.5); padding: 3px;
}
#loading-bar {
  height: 100%; width: 0%; border-radius: 5px;
  background: linear-gradient(90deg, var(--gold), #f6d87c);
  transition: width 0.15s;
}

/* ---------- keys help ---------- */
.keys-table { margin: 8px auto 0; border-collapse: collapse; }
.keys-table td { padding: 4px 12px; font-size: 15px; text-align: left; }
.keys-table td:first-child { text-align: right; }
kbd {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  background: #fffdf6; border: 1px solid #b09a6a; border-bottom-width: 3px;
  font-family: var(--font-en); font-size: 13px; color: var(--ink);
}

/* ============================================================
   Touch controls
   ============================================================ */
#touch { position: absolute; inset: 0; z-index: 12; pointer-events: none; }
#touch-left {
  position: absolute; left: 3vw; bottom: 4vh;
  display: flex; gap: 14px;
}
#touch-right {
  position: absolute; right: 3vw; bottom: 4vh;
  display: flex; gap: 14px; align-items: flex-end;
}
.tbtn {
  pointer-events: auto;
  width: 74px; height: 74px; border-radius: 50%;
  border: 3px solid rgba(232, 185, 60, 0.75);
  background: rgba(30, 20, 14, 0.5);
  color: #ffe9b8; font-size: 26px; font-family: var(--font-zh);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.tbtn span { font-size: 11px; font-family: var(--font-en); opacity: 0.7; }
.tbtn:active { background: rgba(164, 35, 42, 0.65); }
.tbtn-small { width: 58px; height: 58px; font-size: 20px; }

/* boss health bar */
#bossbar {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  width: min(460px, 60vw); z-index: 11; text-align: center; pointer-events: none;
}
#bossbar .bname { color: #ffd9d0; text-shadow: 0 2px 3px #000; margin-bottom: 4px; }
#bossbar .bname .zh { font-size: 22px; font-family: var(--font-zh); display: inline; }
#bossbar .bname .en { font-size: 13px; display: inline; margin-left: 8px; }
#bossbar .btrack {
  height: 16px; border: 2px solid #5c0f14; border-radius: 8px;
  background: rgba(0,0,0,0.55); padding: 2px;
}
#bossbar .bfill {
  height: 100%; border-radius: 5px; width: 100%;
  background: linear-gradient(180deg, #ff6a4e, #c11f10);
  transition: width 0.2s;
}

@media (max-width: 720px) {
  #hud-healthbar { width: 160px; height: 18px; }
  #hud-hearts, .hud-heart { height: 22px; }
  .hud-heart { width: 22px; }
  .paper { padding: 18px 20px; }
  .tbtn { width: 62px; height: 62px; font-size: 22px; }
}
