:root {
  --bg: #0b0f1a;
  --panel: #12182a;
  --panel2: #1a2238;
  --border: #2a3555;
  --gold: #e8c547;
  --gold-dim: #a8892e;
  --cyan: #4ecdc4;
  --pink: #ff6b9d;
  --purple: #9b6dff;
  --green: #5ddea3;
  --red: #ff5c7a;
  --text: #e8ecf4;
  --muted: #8b95b0;
  --shadow: 0 8px 32px rgba(0,0,0,.45);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100%;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: radial-gradient(ellipse at top, #151c30 0%, var(--bg) 70%);
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.screen.active { display: flex; }

/* ===== TITLE ===== */
#screen-title {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 20%, rgba(155,109,255,.25), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(78,205,196,.15), transparent 40%),
    var(--bg);
}
.title-logo {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: .08em;
  background: linear-gradient(135deg, var(--gold), #fff, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(232,197,71,.3);
  margin-bottom: 6px;
}
.title-sub {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 40px;
  letter-spacing: .2em;
  text-transform: uppercase;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, opacity .15s;
  min-height: 48px;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--purple), #6b4ce0);
  color: #fff;
  box-shadow: 0 4px 20px rgba(155,109,255,.4);
  width: 100%;
  max-width: 280px;
  margin: 8px 0;
}
.btn-secondary {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 280px;
  margin: 8px 0;
}
.btn-danger {
  background: linear-gradient(135deg, var(--red), #c43a55);
  color: #fff;
}
.btn-sm {
  padding: 8px 16px;
  font-size: .85rem;
  min-height: 36px;
}
.btn:disabled { opacity: .45; pointer-events: none; }

/* ===== CREATE ===== */
#screen-create {
  padding: 20px 16px;
  overflow-y: auto;
}
.screen-header {
  text-align: center;
  margin-bottom: 20px;
}
.screen-header h2 {
  font-size: 1.4rem;
  color: var(--gold);
}
.screen-header p { color: var(--muted); font-size: .85rem; margin-top: 4px; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.form-group input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
.form-group input:focus { border-color: var(--purple); }

.class-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.class-card {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.class-card.selected {
  border-color: var(--gold);
  background: linear-gradient(160deg, rgba(232,197,71,.12), var(--panel));
}
.class-card .icon { font-size: 1.8rem; margin-bottom: 6px; }
.class-card .name { font-weight: 700; font-size: .95rem; }
.class-card .desc { font-size: .72rem; color: var(--muted); margin-top: 4px; line-height: 1.3; }

/* ===== HUD / GAME ===== */
#screen-game {
  display: none;
  flex-direction: column;
}
#screen-game.active { display: flex; }

.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  border: 2px solid var(--gold-dim);
}
.player-meta { flex: 1; min-width: 0; }
.player-meta .name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: .95rem;
}
.rank-badge {
  font-size: .65rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--gold);
  color: #1a1400;
  font-weight: 800;
}
.bars { margin-top: 4px; }
.bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}
.bar-label { font-size: .65rem; color: var(--muted); width: 24px; }
.bar-track {
  flex: 1;
  height: 8px;
  background: #0a0e18;
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 4px; transition: width .3s; }
.bar-hp { background: linear-gradient(90deg, #c43a55, var(--red)); }
.bar-mp { background: linear-gradient(90deg, #2a6bc4, #4a9fff); }
.bar-xp { background: linear-gradient(90deg, var(--gold-dim), var(--gold)); }
.bar-val { font-size: .6rem; color: var(--muted); width: 52px; text-align: right; }

.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* MAP */
.map-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(78,205,196,.08), transparent 50%),
    radial-gradient(ellipse at 70% 70%, rgba(155,109,255,.1), transparent 45%),
    #0d1220;
}
.map-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
}
.map-canvas {
  position: relative;
  width: 640px;
  height: 720px;
  margin: 0 auto;
}
.map-bg-label {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .75rem;
  color: var(--muted);
  letter-spacing: .15em;
  text-transform: uppercase;
  z-index: 1;
  pointer-events: none;
}
.node {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  z-index: 2;
  box-shadow: var(--shadow);
}
.node:active { transform: scale(.92); }
.node.current {
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(232,197,71,.45);
}
.node.reachable { border-color: var(--cyan); }
.node.locked { opacity: .4; pointer-events: none; }
.node .node-icon { font-size: 1.4rem; line-height: 1; }
.node .node-name {
  font-size: .58rem;
  margin-top: 2px;
  color: var(--muted);
  max-width: 64px;
  text-align: center;
  line-height: 1.1;
}
.path-line {
  position: absolute;
  height: 3px;
  background: linear-gradient(90deg, var(--border), var(--panel2));
  transform-origin: left center;
  z-index: 1;
  border-radius: 2px;
}

/* BOTTOM NAV */
.bottom-nav {
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding: 4px 0 env(safe-area-inset-bottom, 4px);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .65rem;
  cursor: pointer;
}
.nav-item.active { color: var(--gold); }
.nav-item .nav-icon { font-size: 1.25rem; }

/* PANELS (overlay) */
.panel-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(5,8,16,.72);
  z-index: 50;
  align-items: flex-end;
  justify-content: center;
}
.panel-overlay.open { display: flex; }
.panel-sheet {
  width: 100%;
  max-height: 82%;
  background: var(--panel);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp .25s ease;
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-head h3 { font-size: 1.05rem; color: var(--gold); }
.panel-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
}

/* STATS */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.stat-box {
  background: var(--panel2);
  border-radius: 10px;
  padding: 12px;
  border: 1px solid var(--border);
}
.stat-box .label { font-size: .7rem; color: var(--muted); }
.stat-box .value { font-size: 1.2rem; font-weight: 700; margin-top: 2px; }
.stat-box .value.gold { color: var(--gold); }

/* INVENTORY */
.inv-list { display: flex; flex-direction: column; gap: 8px; }
.inv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel2);
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}
.inv-item .ii { font-size: 1.4rem; }
.inv-item .info { flex: 1; min-width: 0; }
.inv-item .info .n { font-weight: 700; font-size: .9rem; }
.inv-item .info .d { font-size: .72rem; color: var(--muted); }
.inv-item .qty {
  background: var(--bg);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--cyan);
}

/* QUEST */
.quest-card {
  background: var(--panel2);
  border-radius: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
}
.quest-card.active-q { border-color: var(--cyan); }
.quest-card.done-q { border-color: var(--green); opacity: .7; }
.quest-card .qt { font-weight: 700; margin-bottom: 4px; }
.quest-card .qd { font-size: .8rem; color: var(--muted); line-height: 1.4; }
.quest-card .qr {
  margin-top: 8px;
  font-size: .75rem;
  color: var(--gold);
}

/* CHAT */
.chat-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.chat-tab {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}
.chat-tab.active {
  background: var(--purple);
  color: #fff;
  border-color: var(--purple);
}
.chat-messages {
  height: 240px;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}
.chat-msg {
  margin-bottom: 8px;
  font-size: .82rem;
  line-height: 1.35;
}
.chat-msg .who {
  font-weight: 700;
  color: var(--cyan);
  margin-right: 4px;
}
.chat-msg .who.system { color: var(--gold); }
.chat-msg .who.self { color: var(--pink); }
.chat-msg .who.rank-s { color: var(--gold); }
.chat-input-row {
  display: flex;
  gap: 8px;
}
.chat-input-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: .9rem;
  outline: none;
}
.pm-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.pm-friend {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--panel2);
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.pm-friend.selected { border-color: var(--purple); }
.pm-friend .av {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
}
.pm-friend .nm { font-weight: 700; font-size: .9rem; }
.pm-friend .st { font-size: .7rem; color: var(--green); }

/* VN DIALOG */
#vn-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 60;
  flex-direction: column;
  justify-content: flex-end;
  background: linear-gradient(to top, rgba(5,8,16,.95) 30%, rgba(5,8,16,.4) 70%, transparent);
}
#vn-overlay.open { display: flex; }
.vn-portrait {
  position: absolute;
  right: 16px;
  bottom: 180px;
  font-size: 5rem;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,.5));
  opacity: .95;
}
.vn-box {
  margin: 0 12px 12px;
  background: rgba(18,24,42,.94);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  backdrop-filter: blur(8px);
}
.vn-name {
  color: var(--gold);
  font-weight: 800;
  font-size: .9rem;
  margin-bottom: 8px;
}
.vn-text {
  font-size: .95rem;
  line-height: 1.5;
  min-height: 60px;
  margin-bottom: 12px;
}
.vn-choices { display: flex; flex-direction: column; gap: 8px; }
.vn-choice {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: .88rem;
  cursor: pointer;
}
.vn-choice:active { background: var(--purple); border-color: var(--purple); }
.vn-next {
  width: 100%;
  margin-top: 4px;
}

/* COMBAT */
#combat-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 70;
  flex-direction: column;
  background: radial-gradient(ellipse at center, #1a1028 0%, #0b0f1a 80%);
}
#combat-overlay.open { display: flex; }
.combat-arena {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 24px;
}
.combat-entity {
  text-align: center;
  width: 100%;
  max-width: 280px;
}
.combat-entity .ce-icon { font-size: 3.5rem; margin-bottom: 8px; }
.combat-entity .ce-name { font-weight: 700; margin-bottom: 6px; }
.combat-log {
  height: 72px;
  overflow-y: auto;
  width: 100%;
  max-width: 360px;
  background: rgba(0,0,0,.35);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.4;
}
.combat-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 16px 20px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.combat-actions .btn { width: 100%; max-width: none; margin: 0; }

/* TOAST */
#toast {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--panel2);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 100;
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* LOCATION INFO */
.loc-banner {
  position: absolute;
  bottom: 70px;
  left: 12px;
  right: 12px;
  background: rgba(18,24,42,.92);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  z-index: 5;
  display: none;
}
.loc-banner.show { display: block; }
.loc-banner h4 { color: var(--cyan); margin-bottom: 4px; }
.loc-banner p { font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
.loc-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty-hint {
  text-align: center;
  color: var(--muted);
  padding: 24px;
  font-size: .9rem;
}

/* v2 */
.btn-sm { width: auto; max-width: none; margin: 0; flex-shrink: 0; }
.inv-item .info { overflow-wrap: anywhere; }
.skpick { display: none; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 6px 12px; }
.skpick.open { display: flex; }

/* ===== v2.1 Fullscreen & Landscape ===== */
html, body, #app { height: 100vh; height: 100dvh; }
#app { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
@media (orientation: landscape) {
  #app { max-width: none; }
  #screen-game.active { display: grid; grid-template-columns: 230px 1fr 68px; grid-template-rows: 100%; }
  .top-bar { grid-column: 1; flex-direction: column; align-items: stretch; border-bottom: none; border-right: 1px solid var(--border); overflow-y: auto; }
  .map-area { grid-column: 2; min-height: 0; }
  .bottom-nav { grid-column: 3; flex-direction: column; justify-content: space-around; border-top: none; border-left: 1px solid var(--border); padding: 4px 0; }
  .panel-overlay { align-items: center; }
  .panel-sheet { max-width: 600px; max-height: 92%; border-radius: 20px; border-bottom: 1px solid var(--border); }
  #combat-overlay .combat-arena { flex-direction: row; justify-content: space-around; gap: 12px; padding: 8px 16px; }
  .combat-log { max-width: 34%; }
  .combat-actions { grid-template-columns: repeat(4, 1fr); padding: 8px 16px; }
  .vn-box { max-width: 760px; width: 100%; margin: 0 auto; }
  .vn-portrait { font-size: 4rem; bottom: 150px; }
  .class-grid { grid-template-columns: repeat(4, 1fr); }
  #screen-title { overflow-y: auto; padding: 12px; }
  .title-logo { font-size: 2rem; }
  .btn { min-height: 40px; padding: 8px 20px; }
  .btn-primary, .btn-secondary { margin: 3px 0; }
  .btn-sm { min-height: 32px; padding: 6px 14px; }
}
