:root {
  --bg-0: #0a0816;
  --bg-1: #14121f;
  --bg-2: #1c1a30;
  --bg-3: #2a2540;
  --gold: #BA7517;
  --gold-bright: #EF9F27;
  --gold-deep: #854F0B;
  --cream: #F5EFE0;
  --ink: #050410;
  --text: #E8E2D0;
  --text-dim: #9A8E72;
  --line: #4A3818;
  --line-dim: #2a2010;
  --purple: #7F77DD;
  --teal: #5DCAA5;
  --rose: #F4C0D1;
  --shadow: rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Georgia", serif;
  background: var(--bg-0);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(127,119,221,0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(239,159,39,0.04) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

/* ============ TITLE SCREEN ============ */
#title-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-0);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: titleFadeIn 0.8s ease;
}
#title-screen.hide {
  animation: titleFadeOut 0.6s ease forwards;
}
@keyframes titleFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes titleFadeOut { from { opacity: 1; } to { opacity: 0; visibility: hidden; } }

.title-art {
  width: 100%;
  max-width: 720px;
  margin-bottom: 28px;
  border: 0.5px solid var(--gold);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(127,119,221,0.12);
}
.title-art svg { display: block; width: 100%; }

.title-name {
  font-size: 48px;
  letter-spacing: 0.3em;
  color: var(--cream);
  margin: 0 0 6px;
  text-align: center;
}
.title-en {
  font-size: 12px;
  letter-spacing: 0.5em;
  color: var(--gold-bright);
  margin: 0 0 18px;
  text-align: center;
}
.title-lead {
  max-width: 540px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 2;
  letter-spacing: 0.12em;
  margin: 0 0 28px;
}
.title-actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.btn-start {
  background: var(--gold-bright);
  border: 0.5px solid var(--gold-deep);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 0.35em;
  padding: 14px 38px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}
.btn-start:hover { background: var(--cream); transform: translateY(-1px); }
.btn-start:active { transform: translateY(0); }
.btn-rules {
  background: transparent;
  border: 0.5px solid var(--gold);
  color: var(--gold-bright);
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.25em;
  padding: 13px 28px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}
.btn-rules:hover { background: var(--bg-2); }

/* ============ TOP BAR ============ */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 14px;
  border-bottom: 0.5px solid var(--line);
  flex-wrap: wrap;
  gap: 12px;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg-2);
  border: 0.5px solid var(--gold);
  color: var(--gold-bright);
  font-size: 22px;
  border-radius: 50%;
  animation: moonPulse 5s ease-in-out infinite;
}
@keyframes moonPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,159,39,0); }
  50% { box-shadow: 0 0 14px 2px rgba(239,159,39,0.18); }
}
.brand-title { font-size: 22px; color: var(--cream); letter-spacing: 0.18em; }
.brand-sub { font-size: 11px; color: var(--text-dim); letter-spacing: 0.4em; }

#nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-btn {
  background: transparent;
  border: 0.5px solid var(--line);
  color: var(--text-dim);
  padding: 9px 20px;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.2em;
  cursor: pointer;
  transition: all 0.18s;
  border-radius: 2px;
}
.nav-btn:hover {
  border-color: var(--gold);
  color: var(--text);
}
.nav-btn.active {
  background: var(--bg-2);
  border-color: var(--gold);
  color: var(--gold-bright);
}
.nav-btn.help {
  width: 36px;
  padding: 9px 0;
  text-align: center;
  font-size: 15px;
}

.status {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.15em;
}
#night-label { color: var(--cream); }
#moon-label {
  color: var(--gold-bright);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#moon-label::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  background: var(--gold-bright);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(239,159,39,0.5);
}
.ghost {
  background: transparent;
  border: 0.5px solid var(--gold);
  color: var(--gold-bright);
  font-family: inherit;
  padding: 7px 14px;
  font-size: 12px;
  letter-spacing: 0.18em;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}
.ghost:hover { background: var(--bg-2); transform: translateY(-1px); }

.screen { display: none; padding-top: 24px; animation: screenFade 0.35s ease; }
.screen.active { display: block; }
@keyframes screenFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.section-title {
  font-size: 17px;
  letter-spacing: 0.3em;
  color: var(--cream);
  margin: 0 0 4px;
}
.section-sub {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.25em;
  margin: 0 0 18px;
}

/* ============ GALLERY ============ */
.gallery-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin: 14px 0 18px;
  padding-bottom: 12px;
  border-bottom: 0.5px solid var(--line-dim);
}
.filter-btn {
  background: transparent;
  border: 0.5px solid var(--line);
  color: var(--text-dim);
  padding: 6px 14px;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.2em;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s;
}
.filter-btn:hover { color: var(--text); }
.filter-btn.active {
  border-color: var(--gold);
  color: var(--gold-bright);
  background: var(--bg-2);
}
.gallery-count {
  margin-left: auto;
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--text-dim);
}
.gallery-count strong {
  color: var(--cream);
  font-weight: normal;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.card-tile {
  background: var(--bg-1);
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.22s, box-shadow 0.22s, filter 0.22s;
  position: relative;
  overflow: hidden;
}
.card-tile:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 10px 28px rgba(0,0,0,0.5), 0 0 0 0.5px var(--gold);
  filter: brightness(1.06);
}
.card-tile svg { display: block; width: 100%; height: auto; }

.card-tile.uncollected { cursor: default; opacity: 0.7; }
.card-tile.uncollected:hover { transform: none; box-shadow: none; opacity: 0.85; filter: none; }
.card-tile .dup-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-0);
  border: 0.5px solid var(--gold);
  color: var(--gold-bright);
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 2px;
  letter-spacing: 0.12em;
}

/* ============ COLLECT (action) ============ */
.collect-stage {
  background: var(--bg-1);
  border: 0.5px solid var(--line);
  border-radius: 6px;
  padding: 18px;
  margin-bottom: 16px;
}
.collect-canvas {
  width: 100%;
  background: var(--ink);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  border: 0.5px solid var(--line-dim);
}
.collect-canvas svg { display: block; width: 100%; height: auto; }
.collect-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 16px;
}
.control-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.control-label {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.control-label .v { color: var(--cream); }
.control-label .hint {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 10px;
  letter-spacing: 0.1em;
  transition: all 0.2s;
}
.hint.up { background: rgba(93,202,165,0.15); color: var(--teal); }
.hint.down { background: rgba(244,192,209,0.12); color: var(--rose); }
.hint.steady { background: var(--bg-3); color: var(--text-dim); }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--gold-bright);
  border-radius: 50%;
  cursor: pointer;
  border: 0.5px solid var(--gold-deep);
  box-shadow: 0 0 8px rgba(239,159,39,0.3);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--gold-bright);
  border-radius: 50%;
  cursor: pointer;
  border: 0.5px solid var(--gold-deep);
  box-shadow: 0 0 8px rgba(239,159,39,0.3);
}

.signal-bar {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.signal-meter {
  height: 8px;
  background: var(--bg-3);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.signal-fill {
  height: 100%;
  background: var(--gold-bright);
  transition: width 0.3s ease;
  width: 0%;
}
.signal-fill.hot {
  background: var(--gold-bright);
  animation: signalPulse 1.4s ease-in-out infinite;
}
@keyframes signalPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,159,39,0); }
  50% { box-shadow: 0 0 14px 2px rgba(239,159,39,0.5); }
}

.collect-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.btn-primary {
  background: var(--gold-bright);
  border: 0.5px solid var(--gold-deep);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.25em;
  padding: 11px 28px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}
.btn-primary:hover:not(:disabled) {
  background: var(--cream);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(239,159,39,0.3);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled {
  background: var(--bg-3);
  color: var(--text-dim);
  border-color: var(--line);
  cursor: not-allowed;
}
.btn-secondary {
  background: transparent;
  border: 0.5px solid var(--line);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.18em;
  padding: 10px 18px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--gold); color: var(--cream); }
.collect-hint {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.15em;
}
.collect-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.phase-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}
.phase-tag strong { color: var(--gold-bright); font-weight: normal; }
.rarity-whisper {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  font-style: italic;
}
.rarity-whisper.show { color: var(--gold-bright); }

/* ============ STAGE ============ */
.stage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.stage-slot {
  background: var(--bg-1);
  border: 0.5px dashed var(--line);
  border-radius: 4px;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  padding: 12px;
  transition: all 0.2s;
}
.stage-slot:hover { border-color: var(--gold); }
.stage-slot.has-card { border-style: solid; border-color: var(--gold); cursor: default; }
.stage-slot .placeholder {
  color: var(--text-dim);
  letter-spacing: 0.4em;
  font-size: 14px;
}
.stage-slot .clear-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--bg-0);
  border: 0.5px solid var(--line);
  color: var(--text-dim);
  font-size: 10px;
  padding: 3px 8px;
  cursor: pointer;
  border-radius: 2px;
  display: none;
  z-index: 2;
}
.stage-slot.has-card .clear-btn { display: block; }
.stage-slot .clear-btn:hover { color: var(--cream); border-color: var(--gold); }
.stage-slot svg { width: 100%; max-width: 320px; height: auto; }

.synergy-panel {
  background: var(--bg-1);
  border: 0.5px solid var(--line);
  border-radius: 4px;
  padding: 18px;
  margin-bottom: 16px;
}
.synergy-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  font-size: 13px;
  border-bottom: 0.5px solid var(--line-dim);
  letter-spacing: 0.1em;
}
.synergy-row:last-child { border-bottom: none; }
.synergy-row strong { color: var(--gold-bright); font-weight: normal; }
.synergy-row.bonus-active strong { color: var(--teal); }
.story-piece {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-0);
  border-left: 2px solid var(--gold);
  border-radius: 2px;
  font-size: 13px;
  line-height: 1.85;
  color: var(--cream);
  font-style: italic;
  letter-spacing: 0.06em;
}

.journal {
  background: var(--bg-1);
  border: 0.5px solid var(--line);
  border-radius: 4px;
  padding: 16px;
}
.journal h3 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.3em;
  color: var(--gold-bright);
  font-weight: normal;
}
.journal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}
.journal-list li {
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 0;
  border-bottom: 0.5px dashed var(--line-dim);
  line-height: 1.7;
  letter-spacing: 0.04em;
}
.journal-list li:last-child { border-bottom: none; }
.journal-list .jrn-meta {
  display: block;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--gold);
  margin-bottom: 4px;
}
.journal-list .jrn-text { color: var(--cream); font-style: italic; }
.journal-empty {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-align: center;
  padding: 24px 0;
}

/* ============ MARKET ============ */
.market-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.market-item {
  background: var(--bg-1);
  border: 0.5px solid var(--line);
  border-radius: 4px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s;
}
.market-item:hover { border-color: var(--gold); }
.market-item svg { width: 100%; height: auto; border-radius: 2px; }
.market-cost {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.18em;
}
.market-cost strong { color: var(--gold-bright); font-weight: normal; }
.market-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 12px;
  border-bottom: 0.5px solid var(--line-dim);
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.shadows-count {
  font-size: 13px;
  color: var(--cream);
  letter-spacing: 0.18em;
}
.shadows-count strong { color: var(--gold-bright); font-weight: normal; font-size: 16px; }

/* ============ MODAL ============ */
#modal.modal-hidden { display: none; }
#modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
#modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.78); animation: modalBgIn 0.25s ease; }
@keyframes modalBgIn { from { opacity: 0; } to { opacity: 1; } }
#modal-body {
  position: relative;
  background: var(--bg-1);
  border: 0.5px solid var(--gold);
  border-radius: 6px;
  max-width: 760px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
  animation: modalIn 0.3s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--cream); }
.modal-card-wrap { display: flex; flex-direction: column; gap: 14px; }
.modal-card-wrap svg { width: 100%; height: auto; }
.modal-info { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 13px; }
.modal-info dt { color: var(--text-dim); letter-spacing: 0.18em; font-size: 11px; margin-bottom: 4px; }
.modal-info dd { margin: 0 0 8px; color: var(--cream); }

/* RULES MODAL CONTENT */
.rules h3 {
  margin: 18px 0 8px;
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--gold-bright);
  font-weight: normal;
  border-bottom: 0.5px solid var(--line-dim);
  padding-bottom: 6px;
}
.rules h3:first-child { margin-top: 0; }
.rules p { font-size: 13px; line-height: 1.9; color: var(--text); letter-spacing: 0.06em; margin: 4px 0; }
.rules .em { color: var(--gold-bright); }
.rules .rule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin: 8px 0;
}
.rules .pill {
  background: var(--bg-2);
  border: 0.5px solid var(--line);
  border-radius: 2px;
  padding: 8px 10px;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text);
}
.rules .pill strong { color: var(--gold-bright); font-weight: normal; }

/* ============ TOAST ============ */
#toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-2);
  border: 0.5px solid var(--gold);
  color: var(--cream);
  padding: 12px 26px;
  border-radius: 4px;
  font-size: 13px;
  letter-spacing: 0.18em;
  z-index: 200;
  transition: transform 0.35s ease;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ============ MOBILE ============ */
@media (max-width: 720px) {
  #app { padding: 0 12px 60px; }
  #topbar { gap: 8px; }
  .brand-sub { display: none; }
  .nav-btn { padding: 6px 12px; font-size: 12px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .stage-grid { grid-template-columns: 1fr; }
  .collect-controls { grid-template-columns: 1fr; }
  .title-name { font-size: 36px; }
  .title-lead { font-size: 13px; }
}
