/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg:        #080810;
  --bg2:       #0d0d1a;
  --bg3:       #12121f;
  --border:    #252540;
  --gold:      #c9a84c;
  --gold-dim:  #7a6530;
  --text:      #e0d8c8;
  --text-dim:  #6e6e90;
  --text-faint:#2e2e4e;
  --red:       #e05252;
  --radius:    6px;
  --font-serif:'Noto Serif SC', serif;
  --font-title:'Cinzel', serif;
  --tab-h:     56px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

/* ── Start Screen ───────────────────────────────────────────────────────── */
#start-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 30%, #1a1040 0%, transparent 60%), var(--bg);
}

.start-inner {
  text-align: center;
  max-width: 520px;
  width: 100%;
  padding: 2rem 1.5rem;
  animation: fadeUp .8s ease both;
}

.start-ornament {
  font-size: 2rem;
  color: var(--gold);
  margin-bottom: .5rem;
  animation: pulse 3s ease infinite;
}

.start-title {
  font-family: var(--font-title);
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  letter-spacing: .18em;
  color: var(--gold);
  text-shadow: 0 0 40px #c9a84c55;
  margin-bottom: .2rem;
}

.start-subtitle {
  font-size: 1.1rem;
  color: var(--text-dim);
  letter-spacing: .4em;
  margin-bottom: 1.6rem;
}

.start-lore {
  color: var(--text-dim);
  line-height: 2;
  margin-bottom: 1.6rem;
  font-size: .92rem;
}

#civ-name-input {
  width: 100%;
  max-width: 320px;
  padding: .75rem 1rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
  margin-bottom: 1.4rem;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
#civ-name-input:focus { border-color: var(--gold); }

.start-device-label {
  font-size: .72rem;
  letter-spacing: .2em;
  color: var(--text-faint);
  font-family: var(--font-title);
  margin-bottom: .8rem;
}

.device-btns {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: .8rem;
}

.device-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  padding: 1.2rem 1.6rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  transition: border-color .2s, background .2s, transform .15s;
  min-width: 120px;
}
.device-btn:hover { border-color: var(--gold); background: #1a1830; transform: translateY(-2px); }
.device-btn:active { transform: scale(.97); }

.db-icon  { font-size: 2rem; }
.db-title { font-family: var(--font-title); font-size: .88rem; color: var(--gold); letter-spacing: .08em; }
.db-sub   { font-size: .7rem; color: var(--text-faint); }

.start-hint { font-size: .75rem; color: var(--text-faint); }

/* ── Game Screen ────────────────────────────────────────────────────────── */
#game-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#game-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem 1rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.header-brand {
  font-family: var(--font-title);
  font-size: .82rem;
  letter-spacing: .2em;
  color: var(--gold-dim);
  flex-shrink: 0;
}

.header-civ {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  flex: 1;
}

.hciv-name  { font-family: var(--font-title); font-size: .95rem; color: var(--gold); }
.hciv-meta  { font-size: .72rem; color: var(--text-dim); }
.hciv-badge {
  font-size: .68rem;
  padding: .12rem .5rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
}

#traits-bar { display: flex; gap: .3rem; flex-wrap: wrap; }

.trait-badge {
  font-size: .62rem;
  padding: .1rem .45rem;
  border-radius: 20px;
  border: 1px solid;
  animation: fadeIn .4s ease;
}

/* ── Desktop: Game Body ──────────────────────────────────────────────────── */
#game-body {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

aside {
  background: var(--bg2);
  overflow-y: auto;
  padding: 1rem .8rem;
}

#left-panel  { border-right: 1px solid var(--border); }
#right-panel { border-left: 1px solid var(--border); }

#mobile-tabs { display: none; }

/* ── Panels (shared) ────────────────────────────────────────────────────── */
.panel-section { margin-bottom: 1.4rem; }

.panel-title {
  font-family: var(--font-title);
  font-size: .7rem;
  letter-spacing: .2em;
  color: var(--gold-dim);
  text-transform: uppercase;
  margin-bottom: .7rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--text-faint);
  display: flex;
  align-items: center;
  gap: .4rem;
}

.panel-count { font-size: .65rem; color: var(--text-faint); margin-left: auto; letter-spacing: 0; }

.empty-msg { font-size: .78rem; color: var(--text-faint); font-style: italic; }

/* Culture Bars */
.bar-row {
  display: grid;
  grid-template-columns: 34px 1fr 28px;
  align-items: center;
  gap: .4rem;
  margin-bottom: .45rem;
}
.bar-label { font-size: .72rem; color: var(--text-dim); }
.bar-track {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--text-faint);
}
.bar-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }
.bar-num  { font-size: .68rem; color: var(--text-faint); text-align: right; }

/* Lexicon */
.lex-entry {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  margin-bottom: .3rem;
  animation: fadeIn .3s ease;
}
.lex-word    { font-family: var(--font-title); font-size: .78rem; color: var(--gold); }
.lex-meaning { font-size: .72rem; color: var(--text-dim); }

/* History */
.hist-entry {
  margin-bottom: .45rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--text-faint);
  animation: fadeIn .3s ease;
}
.hist-entry.hist-major .hist-text { color: var(--gold); }
.hist-year {
  display: block;
  font-size: .62rem;
  color: var(--text-faint);
  font-family: var(--font-title);
  letter-spacing: .06em;
  margin-bottom: .1rem;
}
.hist-text { font-size: .76rem; color: var(--text-dim); line-height: 1.4; }

/* ── Main Panel ─────────────────────────────────────────────────────────── */
#main-panel {
  overflow-y: auto;
  padding: 2rem 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: radial-gradient(ellipse at 50% 0%, #1a1040 0%, transparent 50%), var(--bg);
}

/* ── Opening Sequence ───────────────────────────────────────────────────── */
.opening-sequence { text-align: center; padding: 3rem 1rem; }
.opening-line {
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
  opacity: 0;
  animation: openingFade 1s ease forwards;
}

/* ── Progress Bar ───────────────────────────────────────────────────────── */
.concept-progress {
  width: 100%;
  max-width: 500px;
  margin-bottom: 1rem;
}
.progress-label {
  font-size: .65rem;
  color: var(--text-faint);
  font-family: var(--font-title);
  letter-spacing: .1em;
  margin-bottom: .3rem;
  display: flex;
  justify-content: space-between;
}
.progress-track {
  height: 3px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  border-radius: 2px;
  transition: width .6s ease;
}

/* ── Naming Moment ──────────────────────────────────────────────────────── */
.naming-moment {
  width: 100%;
  max-width: 640px;
  text-align: center;
  animation: fadeUp .4s ease both;
}
.concept-era {
  font-family: var(--font-title);
  font-size: .68rem;
  letter-spacing: .2em;
  color: var(--text-faint);
  margin-bottom: .5rem;
}
.concept-name {
  font-family: var(--font-title);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  color: var(--gold);
  text-shadow: 0 0 30px #c9a84c44;
  margin-bottom: .7rem;
  letter-spacing: .08em;
}
.concept-desc {
  font-size: .88rem;
  color: var(--text-dim);
  line-height: 1.9;
  max-width: 480px;
  margin: 0 auto 1.6rem;
}

.word-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1.1rem;
}
.word-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .9rem .7rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s;
  color: var(--text);
  font-family: var(--font-serif);
  animation: fadeUp .4s ease both;
  gap: .25rem;
  touch-action: manipulation;
}
.word-btn:hover  { border-color: var(--gold); background: #1a1830; transform: translateY(-2px); }
.word-btn:active { transform: scale(.97); }
.word-btn:disabled { opacity: .4; cursor: default; transform: none; }

.wb-word     { font-family: var(--font-title); font-size: 1.3rem; color: var(--gold); letter-spacing: .1em; }
.wb-phonetic { font-size: .65rem; color: var(--text-faint); letter-spacing: .04em; }
.wb-hint     { font-size: .72rem; color: var(--text-dim); margin-top: .05rem; }

/* Custom word */
.custom-row {
  display: flex;
  gap: .6rem;
  justify-content: center;
  margin-top: .7rem;
}
.custom-row input {
  flex: 1;
  max-width: 280px;
  padding: .6rem .9rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-title);
  font-size: .88rem;
  letter-spacing: .1em;
  outline: none;
  transition: border-color .2s;
}
.custom-row input:focus { border-color: var(--gold); }
.custom-row input::placeholder { font-family: var(--font-serif); font-size: .75rem; letter-spacing: 0; }

#custom-submit {
  padding: .6rem 1rem;
  background: transparent;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--gold);
  font-family: var(--font-title);
  font-size: .75rem;
  letter-spacing: .1em;
  cursor: pointer;
  transition: background .2s, border-color .2s;
  touch-action: manipulation;
}
#custom-submit:hover    { background: #c9a84c18; border-color: var(--gold); }
#custom-submit:disabled { opacity: .4; cursor: default; }

.input-error {
  font-size: .73rem;
  color: var(--red);
  margin-top: .35rem;
  min-height: 1rem;
  opacity: 0;
  transition: opacity .3s;
}

/* Narrative Box */
.narrative-box {
  width: 100%;
  max-width: 560px;
  margin-top: 1.4rem;
  padding: .9rem 1.1rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold-dim);
  border-radius: var(--radius);
  min-height: 58px;
  line-height: 1.8;
}
.narr-word { font-family: var(--font-title); color: var(--gold); margin-right: .5rem; font-size: .88rem; }
.narr-text { color: var(--text-dim); font-size: .83rem; }

/* ── Event Moment ───────────────────────────────────────────────────────── */
.event-moment {
  width: 100%;
  max-width: 600px;
  text-align: center;
  animation: fadeUp .5s ease both;
}
.event-deco {
  font-family: var(--font-title);
  font-size: .68rem;
  letter-spacing: .3em;
  color: var(--gold-dim);
  margin-bottom: .7rem;
}
.event-title {
  font-family: var(--font-title);
  font-size: clamp(1.4rem, 4vw, 2rem);
  color: var(--gold);
  margin-bottom: 1.1rem;
  text-shadow: 0 0 30px #c9a84c55;
}
.event-narrative {
  color: var(--text-dim);
  font-size: .88rem;
  line-height: 2;
  margin-bottom: 1.8rem;
  padding: 0 .5rem;
}
.choices-label {
  font-size: .72rem;
  letter-spacing: .15em;
  color: var(--text-faint);
  margin-bottom: .7rem;
  font-family: var(--font-title);
}
.choices-grid { display: flex; flex-direction: column; gap: .55rem; }

.choice-btn {
  padding: .85rem 1.1rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: .86rem;
  cursor: pointer;
  text-align: left;
  transition: border-color .2s, background .2s, transform .15s;
  animation: fadeUp .4s ease both;
  touch-action: manipulation;
}
.choice-btn:hover  { border-color: var(--gold); background: #1a1830; transform: translateX(4px); }
.choice-btn:active { transform: scale(.98); }
.choice-btn:disabled { opacity: .4; cursor: default; transform: none; }

/* Choice Confirmed */
.choice-confirmed {
  text-align: center;
  padding: 2.5rem 1rem;
  animation: fadeUp .4s ease both;
}
.choice-text { font-size: 1rem; color: var(--gold); font-family: var(--font-title); }
.ripple-ring {
  width: 80px; height: 80px;
  border: 2px solid var(--gold-dim);
  border-radius: 50%;
  margin: 1.5rem auto 0;
  animation: ripple 1.6s ease forwards;
}

/* Loading Dots */
.loading-dots { display: flex; justify-content: center; gap: .4rem; margin: 1.5rem 0; }
.loading-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--gold-dim);
  animation: dotPulse 1.2s ease infinite;
}
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }

/* ── End Game ───────────────────────────────────────────────────────────── */
.end-game { text-align: center; max-width: 500px; padding: 2rem; animation: fadeUp .5s ease both; }
.end-game h2 { font-family: var(--font-title); font-size: clamp(1.6rem, 4vw, 2.2rem); color: var(--gold); margin: 1rem 0 .5rem; }
.eg-desc { color: var(--text-dim); font-size: .88rem; line-height: 1.9; }
.eg-traits { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; margin: 1rem 0; }
.restart-btn {
  margin-top: 1.5rem;
  padding: .7rem 2rem;
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-family: var(--font-title);
  font-size: .82rem;
  letter-spacing: .15em;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .2s;
}
.restart-btn:hover { background: #c9a84c18; }

/* ── Toast Notifications ────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg2);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-family: var(--font-title);
  font-size: .78rem;
  letter-spacing: .08em;
  padding: .55rem 1.2rem;
  border-radius: 20px;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Mobile Tab Bar ─────────────────────────────────────────────────────── */
#mobile-tabs {
  display: none;
  flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  height: var(--tab-h);
  display: none;
  grid-template-columns: repeat(3, 1fr);
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .2rem;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  transition: color .2s;
  touch-action: manipulation;
  padding: .3rem;
}
.tab-btn.active { color: var(--gold); }
.tab-icon  { font-size: 1.1rem; line-height: 1; }
.tab-label { font-size: .62rem; font-family: var(--font-title); letter-spacing: .08em; }

/* ── MOBILE MODE ────────────────────────────────────────────────────────── */
body.mobile-mode #game-body {
  grid-template-columns: 1fr;
  position: relative;
}

body.mobile-mode #left-panel,
body.mobile-mode #right-panel,
body.mobile-mode #main-panel {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  border: none;
  padding: 1rem;
}

body.mobile-mode #main-panel {
  padding: 1.2rem 1rem;
  justify-content: flex-start;
}

body.mobile-mode .panel-visible {
  display: flex !important;
  flex-direction: column;
}

body.mobile-mode #main-panel.panel-visible {
  display: flex !important;
}

body.mobile-mode #mobile-tabs { display: grid; }

body.mobile-mode .desktop-only { display: none; }

body.mobile-mode .naming-moment,
body.mobile-mode .event-moment { max-width: 100%; }

body.mobile-mode .concept-name { font-size: 1.6rem; }

body.mobile-mode .word-grid { gap: .6rem; }

body.mobile-mode .word-btn { padding: .85rem .6rem; }

body.mobile-mode .wb-word { font-size: 1.15rem; }

body.mobile-mode .custom-row input { max-width: 100%; }

body.mobile-mode #game-header { padding: .4rem .8rem; }

body.mobile-mode .header-brand { font-size: .72rem; }

body.mobile-mode .hciv-name { font-size: .85rem; }

/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes openingFade {
  0%   { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: .6; }
  50%       { opacity: 1; }
}
@keyframes dotPulse {
  0%, 100% { transform: scale(.6); opacity: .4; }
  50%       { transform: scale(1);  opacity: 1; }
}
@keyframes ripple {
  0%   { transform: scale(1);  opacity: .8; }
  100% { transform: scale(3);  opacity: 0; }
}
.fade-in { animation: fadeIn .6s ease both; }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-faint); border-radius: 2px; }
