/* =========================================================
   Fantasy Village Explorer · UI 样式
   统一的中世纪奇幻风：羊皮纸、暗金、深林绿
   ========================================================= */
:root {
  --gold: #d8b46a;
  --gold-bright: #f4dc9c;
  --gold-dim: #8c7442;
  --parchment: #f0e2c4;
  --parchment-dim: #c9b894;
  --ink: #1a1410;
  --panel: rgba(18, 20, 17, 0.72);
  --panel-solid: rgba(24, 26, 22, 0.94);
  --panel-border: rgba(216, 180, 106, 0.42);
  --green: #7fb069;
  --red: #c4574b;
  --blue: #6fa8c9;
  --shadow: 0 10px 36px rgba(0, 0, 0, 0.55);
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, "Songti SC", "SimSun", serif;
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #0b0f0c; color: var(--parchment);
  font-family: var(--sans);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#game-canvas { display: block; width: 100%; height: 100%; outline: none; }

.hidden { display: none !important; }

/* ---------------- 加载界面 ---------------- */
.loading-screen {
  position: absolute; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 50% 38%, rgba(74, 96, 66, 0.35), transparent 55%),
    radial-gradient(circle at 50% 110%, rgba(216, 180, 106, 0.12), transparent 60%),
    linear-gradient(180deg, #0c1310 0%, #131a13 45%, #0a0d0a 100%);
  transition: opacity 0.9s ease;
}
.loading-screen.fade-out { opacity: 0; pointer-events: none; }
.loading-glow {
  position: absolute; width: 78vmin; height: 78vmin; border-radius: 50%;
  border: 1px solid rgba(216, 180, 106, 0.14);
  box-shadow: 0 0 120px rgba(216, 180, 106, 0.07) inset, 0 0 90px rgba(120, 180, 120, 0.05);
  animation: breathe 6s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { transform: scale(1); opacity: .55; } 50% { transform: scale(1.06); opacity: .85; } }
.loading-content { position: relative; text-align: center; padding: 24px; max-width: 720px; }
.loading-emblem { font-size: 34px; color: var(--gold); letter-spacing: 12px; opacity: .9; margin-bottom: 8px; text-shadow: 0 0 24px rgba(216,180,106,.55); }
.game-title {
  font-family: var(--serif); font-weight: 500; font-size: clamp(30px, 5.2vw, 58px);
  letter-spacing: 0.06em; margin: 0 0 6px;
  background: linear-gradient(180deg, #f7e8bd 0%, #d8b46a 55%, #9c7c3e 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 2px 30px rgba(216, 180, 106, 0.18);
}
.game-subtitle { font-family: var(--serif); letter-spacing: .5em; text-indent: .5em; color: var(--parchment-dim); font-size: 14px; margin: 0 0 40px; }
.loading-bar {
  width: min(420px, 74vw); height: 3px; margin: 0 auto 14px; border-radius: 3px;
  background: rgba(240, 226, 196, 0.12); overflow: hidden; position: relative;
}
#loading-fill {
  height: 100%; width: 0%; border-radius: 3px;
  background: linear-gradient(90deg, #8c7442, #d8b46a 60%, #f7e8bd);
  box-shadow: 0 0 14px rgba(216, 180, 106, 0.7);
  transition: width .3s ease;
}
.loading-text { color: var(--parchment-dim); font-size: 13px; letter-spacing: .12em; min-height: 18px; margin: 0 0 26px; }
.loading-tip { margin-top: 30px; font-size: 12px; letter-spacing: .08em; color: rgba(240, 226, 196, 0.4); }
.start-btn {
  font-family: var(--serif); font-size: 17px; letter-spacing: .22em; color: #1c1710;
  background: linear-gradient(180deg, #f4dc9c, #d8b46a 70%, #b18f4d);
  border: 1px solid #f7e8bd; border-radius: 3px;
  padding: 13px 42px; cursor: pointer; box-shadow: 0 6px 26px rgba(216, 180, 106, 0.35);
  transition: transform .18s ease, box-shadow .18s ease;
}
.start-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 34px rgba(216, 180, 106, 0.5); }

/* ---------------- HUD 基础 ---------------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.hud-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.player-panel { position: absolute; top: 20px; left: 20px; display: flex; gap: 12px; padding: 12px 16px 12px 12px; min-width: 262px; }
.avatar-slot {
  width: 54px; height: 54px; border-radius: 3px; flex: 0 0 auto;
  border: 1px solid var(--panel-border); overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #43563f, #1a231b);
}
.avatar-inner { width: 100%; height: 100%; background:
  radial-gradient(circle at 50% 34%, #d9b98f 0 22%, transparent 23%),
  radial-gradient(ellipse at 50% 78%, #3d5a4a 0 34%, transparent 35%),
  radial-gradient(circle at 50% 14%, #5a4630 0 18%, transparent 19%);
  position: relative;
}
.avatar-inner::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 18px rgba(0,0,0,.6); }
.player-meta { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.player-name { font-family: var(--serif); font-size: 15px; color: var(--gold-bright); letter-spacing: .06em; font-weight: 600; }
.bar-row { display: flex; align-items: center; gap: 7px; }
.bar-label { font-size: 10px; color: var(--parchment-dim); width: 26px; letter-spacing: .1em; }
.bar { flex: 1; height: 6px; border-radius: 4px; background: rgba(240, 226, 196, 0.12); overflow: hidden; }
.bar-fill { height: 100%; width: 100%; border-radius: 4px; transition: width .35s ease; }
.bar-fill.health { background: linear-gradient(90deg, #7c2f28, #c4574b 60%, #e07a63); }
.bar-fill.stamina { background: linear-gradient(90deg, #4a6b3f, #7fb069 60%, #a6cf86); }
.gold-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--gold-bright); }
.coin { color: var(--gold); font-size: 11px; }
.gold-label { color: var(--parchment-dim); font-size: 10px; letter-spacing: .1em; }

.hud-topleft-right { position: absolute; top: 20px; right: 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.clock-panel { padding: 9px 14px; min-width: 160px; }
.clock-row { display: flex; align-items: baseline; gap: 8px; }
.time-icon { color: var(--gold); font-size: 14px; }
.clock-text { font-family: var(--serif); font-size: 19px; color: var(--parchment); letter-spacing: .04em; }
.day-text { font-size: 10px; color: var(--parchment-dim); margin-left: auto; letter-spacing: .1em; }
.weather-row { display: flex; gap: 6px; font-size: 10px; color: var(--parchment-dim); margin-top: 3px; letter-spacing: .12em; }
.divider { opacity: .4; }
.minimap-panel { padding: 6px; border-radius: 50%; position: relative; }
#minimap { display: block; width: 152px; height: 152px; border-radius: 50%; }
.minimap-compass {
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: var(--gold); font-family: var(--serif); letter-spacing: .1em;
}

.quest-tracker {
  position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
  min-width: 250px; max-width: 380px; padding: 10px 18px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 3px;
  backdrop-filter: blur(8px); text-align: center; box-shadow: var(--shadow);
}
.quest-title { font-size: 9px; letter-spacing: .32em; color: var(--gold-dim); text-transform: uppercase; }
.quest-name { font-family: var(--serif); font-size: 14px; color: var(--gold-bright); margin-top: 3px; }
.quest-desc { font-size: 11px; color: var(--parchment-dim); margin-top: 3px; line-height: 1.5; }

.hud-bottomleft {
  position: absolute; left: 20px; bottom: 18px; display: flex; flex-wrap: wrap; gap: 6px 14px;
  max-width: 340px; opacity: .82;
}
.key-hint { font-size: 10px; color: rgba(240, 226, 196, 0.62); letter-spacing: .04em; display: flex; align-items: center; gap: 5px; }
.key {
  display: inline-block; padding: 2px 6px; border-radius: 3px; font-size: 9px; letter-spacing: .08em;
  color: var(--gold-bright); background: rgba(216, 180, 106, 0.1);
  border: 1px solid rgba(216, 180, 106, 0.32); font-family: var(--sans);
}

.interact-prompt {
  position: absolute; left: 50%; bottom: 17%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 9px; padding: 8px 16px 8px 8px;
  background: rgba(16, 18, 15, 0.82); border: 1px solid var(--panel-border); border-radius: 30px;
  backdrop-filter: blur(6px); box-shadow: 0 6px 22px rgba(0,0,0,.45);
  animation: promptIn .22s ease;
}
@keyframes promptIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.prompt-key { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; border-radius: 50%; padding: 0; font-size: 11px; }
.prompt-text { font-size: 13px; color: var(--parchment); letter-spacing: .08em; }

.toast-stack { position: absolute; left: 50%; top: 16%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  padding: 8px 20px; font-size: 12px; letter-spacing: .06em; color: var(--parchment);
  background: rgba(18, 20, 17, 0.86); border: 1px solid var(--panel-border); border-radius: 2px;
  box-shadow: var(--shadow); animation: toastIn .3s ease;
}
.toast.gold { color: var(--gold-bright); border-color: rgba(216,180,106,.7); }
.toast.fade { opacity: 0; transform: translateY(-8px); transition: all .45s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.crosshair { position: absolute; left: 50%; top: 50%; width: 5px; height: 5px; border-radius: 50%; background: rgba(244, 220, 156, .75); transform: translate(-50%, -50%); box-shadow: 0 0 6px rgba(0,0,0,.8); }
.fps { position: absolute; right: 12px; bottom: 10px; font-size: 10px; color: rgba(240, 226, 196, 0.4); font-family: monospace; }

/* ---------------- 对话 ---------------- */
.dialog-panel {
  position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%);
  width: min(780px, 92vw); display: flex; gap: 18px; padding: 20px 22px;
  background: linear-gradient(180deg, rgba(24,26,21,.96), rgba(14,16,13,.97));
  border: 1px solid var(--panel-border); border-radius: 4px;
  box-shadow: 0 24px 70px rgba(0,0,0,.7), inset 0 1px 0 rgba(244,220,156,.08);
  z-index: 40; animation: dialogIn .25s ease;
}
@keyframes dialogIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }
.dialog-portrait {
  width: 74px; height: 74px; flex: 0 0 auto; border: 1px solid var(--panel-border); border-radius: 3px;
  background: radial-gradient(circle at 50% 30%, #3f5340, #171d17); overflow: hidden; position: relative;
}
.portrait-inner { position: absolute; inset: 0; }
.dialog-body { flex: 1; min-width: 0; }
.dialog-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.dialog-name { font-family: var(--serif); font-size: 17px; color: var(--gold-bright); letter-spacing: .06em; }
.dialog-role { font-size: 10px; color: var(--parchment-dim); letter-spacing: .18em; }
.dialog-text { font-size: 14px; line-height: 1.85; color: var(--parchment); min-height: 52px; letter-spacing: .02em; }
.dialog-text .caret { display: inline-block; width: 7px; color: var(--gold); animation: blink .8s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }
.dialog-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.choice-btn {
  font-family: var(--sans); font-size: 12px; color: var(--parchment); letter-spacing: .04em;
  background: rgba(216, 180, 106, 0.08); border: 1px solid rgba(216, 180, 106, 0.32);
  padding: 7px 14px; border-radius: 2px; cursor: pointer; transition: all .16s ease;
}
.choice-btn:hover { background: rgba(216, 180, 106, 0.2); border-color: var(--gold); color: var(--gold-bright); }
.choice-btn .choice-icon { color: var(--gold); margin-right: 6px; }
.dialog-close {
  position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--parchment-dim);
  font-size: 14px; cursor: pointer; padding: 4px; line-height: 1;
}
.dialog-close:hover { color: var(--gold-bright); }

/* ---------------- 商店 ---------------- */
.shop-panel {
  position: absolute; right: 4%; top: 50%; transform: translateY(-50%);
  width: min(400px, 92vw); background: var(--panel-solid);
  border: 1px solid var(--panel-border); border-radius: 4px; box-shadow: var(--shadow);
  z-index: 42; overflow: hidden;
}
.shop-header { display: flex; align-items: center; justify-content: space-between; padding: 15px 20px; border-bottom: 1px solid rgba(216,180,106,.2); }
.shop-title { font-family: var(--serif); font-size: 17px; color: var(--gold-bright); letter-spacing: .06em; }
.shop-gold { font-size: 12px; color: var(--gold); }
.shop-items { max-height: 52vh; overflow-y: auto; padding: 10px 12px; }
.shop-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 10px; border-radius: 3px; cursor: pointer;
  transition: background .15s ease; border: 1px solid transparent;
}
.shop-item:hover { background: rgba(216,180,106,.07); border-color: rgba(216,180,106,.22); }
.shop-item-icon {
  width: 38px; height: 38px; flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  font-size: 19px; background: rgba(216,180,106,.08); border: 1px solid rgba(216,180,106,.22); border-radius: 2px;
}
.shop-item-name { font-size: 13px; color: var(--parchment); }
.shop-item-desc { font-size: 10px; color: var(--parchment-dim); margin-top: 2px; }
.shop-item-price { margin-left: auto; font-size: 12px; color: var(--gold-bright); }
.shop-item-price.cant { color: var(--red); }
.shop-footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-top: 1px solid rgba(216,180,106,.2); }
.shop-tip { font-size: 10px; color: var(--parchment-dim); letter-spacing: .08em; }

/* ---------------- 通用按钮 ---------------- */
.btn {
  font-family: var(--sans); font-size: 12px; letter-spacing: .1em; color: var(--parchment);
  background: rgba(240, 226, 196, 0.06); border: 1px solid rgba(216, 180, 106, 0.32);
  padding: 10px 18px; border-radius: 2px; cursor: pointer; transition: all .16s ease;
}
.btn:hover { background: rgba(216, 180, 106, 0.16); border-color: var(--gold); color: var(--gold-bright); }
.btn-primary { background: linear-gradient(180deg, #e8cf93, #c19c54); color: #1c1710; border-color: #f4dc9c; font-weight: 600; }
.btn-primary:hover { background: linear-gradient(180deg, #f7e8bd, #d8b46a); color: #14100a; }
.btn-ghost { background: transparent; }

/* ---------------- 菜单 ---------------- */
.menu-overlay, .map-overlay {
  position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 9, 7, 0.74); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
}
.menu-card {
  width: min(520px, 92vw); max-height: 92vh; overflow-y: auto; padding: 28px 30px 24px;
  background: linear-gradient(180deg, rgba(26,28,23,.98), rgba(14,16,13,.99));
  border: 1px solid var(--panel-border); border-radius: 5px; box-shadow: 0 30px 90px rgba(0,0,0,.75);
  text-align: center;
}
.menu-emblem { color: var(--gold); font-size: 22px; letter-spacing: 8px; opacity: .85; }
.menu-title { font-family: var(--serif); font-weight: 400; font-size: 22px; letter-spacing: .14em; color: var(--parchment); margin: 8px 0 24px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.menu-grid .btn-primary { grid-column: span 2; }
.menu-section { text-align: left; margin-bottom: 16px; }
.menu-section-title { font-size: 10px; letter-spacing: .24em; color: var(--gold-dim); margin-bottom: 8px; text-transform: uppercase; }
.segmented { display: grid; grid-auto-flow: column; gap: 1px; background: rgba(216,180,106,.16); border: 1px solid rgba(216,180,106,.24); border-radius: 2px; overflow: hidden; }
.seg {
  padding: 9px 6px; font-size: 11px; color: var(--parchment-dim); background: rgba(18,20,16,.9);
  border: none; cursor: pointer; letter-spacing: .06em; transition: all .15s ease;
}
.seg:hover { color: var(--parchment); background: rgba(216,180,106,.1); }
.seg.active { background: rgba(216,180,106,.22); color: var(--gold-bright); }
.menu-controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px 12px; margin-top: 20px; padding-top: 16px; border-top: 1px solid rgba(216,180,106,.14); font-size: 10px; color: var(--parchment-dim); text-align: left; }

/* ---------------- 地图 ---------------- */
.map-overlay { flex-direction: column; gap: 18px; }
#big-map {
  width: min(70vh, 78vw); height: min(70vh, 78vw); border: 1px solid var(--panel-border);
  border-radius: 4px; box-shadow: 0 30px 80px rgba(0,0,0,.7);
}
.map-title { font-family: var(--serif); font-size: 16px; letter-spacing: .3em; color: var(--gold); text-indent: .3em; }
.map-close { margin-top: 0; }

/* ---------------- 移动端 ---------------- */
.mobile-controls { position: absolute; inset: 0; z-index: 25; pointer-events: none; }
.joystick-zone { position: absolute; left: 26px; bottom: 30px; width: 132px; height: 132px; pointer-events: auto; }
.joystick-base {
  width: 132px; height: 132px; border-radius: 50%;
  background: rgba(18,20,17,.42); border: 1px solid rgba(216,180,106,.28);
  position: relative; backdrop-filter: blur(4px);
}
.joystick-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; border-radius: 50%;
  background: rgba(216,180,106,.28); border: 1px solid rgba(244,220,156,.5);
  transform: translate(-50%, -50%);
}
.mobile-buttons { position: absolute; right: 22px; bottom: 34px; display: flex; align-items: flex-end; gap: 14px; pointer-events: auto; }
.mbtn {
  width: 58px; height: 58px; border-radius: 50%; font-family: var(--serif); font-size: 16px;
  color: var(--gold-bright); background: rgba(18,20,17,.5); border: 1px solid rgba(216,180,106,.38);
  backdrop-filter: blur(4px);
}
.mbtn:active { background: rgba(216,180,106,.28); }
.mbtn-big { width: 72px; height: 72px; font-size: 14px; }

/* ---------------- 淡入淡出 ---------------- */
.fade-layer { position: absolute; inset: 0; z-index: 55; background: #050705; opacity: 0; pointer-events: none; transition: opacity .45s ease; }

/* ---------------- 小屏适配 ---------------- */
@media (max-width: 900px) {
  .player-panel { top: 12px; left: 12px; min-width: 0; padding: 9px 12px 9px 9px; }
  .avatar-slot { width: 42px; height: 42px; }
  .player-name { font-size: 13px; }
  .hud-topleft-right { top: 12px; right: 12px; gap: 8px; }
  .clock-panel { min-width: 136px; padding: 7px 11px; }
  .clock-text { font-size: 16px; }
  #minimap { width: 108px; height: 108px; }
  .hud-bottomleft { display: none; }
  .quest-tracker { top: auto; bottom: 150px; min-width: 200px; max-width: 74vw; padding: 8px 12px; }
  .quest-name { font-size: 12px; }
  .quest-desc { font-size: 10px; }
  .dialog-panel { bottom: 2%; padding: 14px; gap: 12px; }
  .dialog-portrait { width: 52px; height: 52px; }
  .dialog-text { font-size: 13px; line-height: 1.7; min-height: 44px; }
  .interact-prompt { bottom: 26%; }
}
@media (max-width: 560px) {
  .game-subtitle { letter-spacing: .28em; font-size: 11px; margin-bottom: 26px; }
  .menu-grid { grid-template-columns: 1fr; }
  .menu-grid .btn-primary { grid-column: span 1; }
  .menu-controls { grid-template-columns: 1fr 1fr; }
  .shop-panel { right: 50%; transform: translate(50%, -50%); top: 50%; }
}