/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0f14;
  --bg2:        #13161f;
  --bg3:        #1c2030;
  --border:     #2a2f45;
  --text:       #c8cfe0;
  --text-dim:   #6b7491;
  --text-head:  #e8ecf4;
  --accent:     #c47c2a;    /* warm amber — moon/fire */
  --accent2:    #3a7bd5;    /* cool blue — StarClan */
  --good:       #4caf6e;
  --danger:     #d05050;
  --info:       #7a8abf;
  --font:       'Georgia', serif;
  --font-ui:    'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
}

/* ── Screens ──────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Title screen ─────────────────────────────────────────────────────── */
#screen-title {
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  background: radial-gradient(ellipse at center, #1a1e2e 0%, #0a0c10 100%);
  position: relative;
  overflow: hidden;
}

.title-art {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.moon {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff8e0, #d4a840 60%, #8c6010);
  box-shadow: 0 0 60px 20px #c4841840, 0 0 120px 40px #c4841820;
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
}

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 15%, #fff 100%, transparent),
    radial-gradient(1px 1px at 25% 8%,  #fff 100%, transparent),
    radial-gradient(1px 1px at 40% 22%, #fff 100%, transparent),
    radial-gradient(1px 1px at 55% 5%,  #fff 100%, transparent),
    radial-gradient(1px 1px at 70% 18%, #fff 100%, transparent),
    radial-gradient(1px 1px at 85% 10%, #fff 100%, transparent),
    radial-gradient(1px 1px at 15% 40%, #fff 100%, transparent),
    radial-gradient(1px 1px at 60% 35%, #fff 100%, transparent),
    radial-gradient(1px 1px at 80% 30%, #fff 100%, transparent),
    radial-gradient(2px 2px at 90% 45%, #ffe 100%, transparent),
    radial-gradient(1px 1px at 35% 55%, #fff 100%, transparent),
    radial-gradient(1px 1px at 5%  60%, #fff 100%, transparent);
  opacity: 0.7;
}

#screen-title h1 {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  color: var(--text-head);
  letter-spacing: 0.12em;
  text-shadow: 0 0 30px #c4841860;
  position: relative;
  z-index: 1;
  margin-top: 200px;
}

.subtitle {
  color: var(--text-dim);
  font-style: italic;
  font-size: 1.1rem;
  position: relative;
  z-index: 1;
}

/* ── Create screen ────────────────────────────────────────────────────── */
#screen-create {
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem;
}

#screen-create h2 {
  font-size: 1.8rem;
  color: var(--accent);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 400px;
}

.form-group label {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

input[type="text"] {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-head);
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--accent); }

/* Pelt swatches */
.pelt-options, .clan-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pelt-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.pelt-swatch:hover { transform: scale(1.1); }
.pelt-swatch.selected { border-color: var(--accent); box-shadow: 0 0 8px var(--accent); }

/* Clan buttons */
.clan-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.95rem;
  transition: background 0.15s, border-color 0.15s;
}
.clan-btn:hover { background: var(--bg2); border-color: var(--text-dim); }
.clan-btn.selected { border-color: var(--accent); color: var(--accent); }

/* Path buttons */
.path-options {
  display: flex;
  gap: 0.6rem;
}

.path-btn {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  transition: background 0.15s, border-color 0.15s;
}
.path-btn:hover { background: var(--bg2); border-color: var(--text-dim); }
.path-btn.selected { border-color: var(--accent); background: #c47c2a12; }
.path-btn .path-label { font-size: 1rem; color: var(--text-head); }
.path-btn .path-desc { font-size: 0.78rem; color: var(--text-dim); font-family: var(--font-ui); }

/* Gender buttons */
.gender-options {
  display: flex;
  gap: 0.6rem;
}

.gender-btn {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.5rem;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.gender-btn:hover { background: var(--bg2); border-color: var(--text-dim); }
.gender-btn.selected { border-color: var(--accent); color: var(--accent); background: #c47c2a18; }

.gender-symbol {
  font-size: 1.05rem;
  line-height: 1;
}

.error-msg { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; }

/* ── Shared buttons ───────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0.7rem 2rem;
  border-radius: 6px;
  font-size: 1rem;
  font-family: var(--font);
  cursor: pointer;
  font-weight: bold;
  letter-spacing: 0.05em;
  transition: opacity 0.2s, transform 0.1s;
  position: relative;
  z-index: 1;
}
.btn-primary:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Game screen ──────────────────────────────────────────────────────── */
#screen-game {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

/* Header */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.2rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}

.cat-name {
  font-size: 1.15rem;
  font-weight: bold;
  color: var(--accent);
}

.cat-rank {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-left: 0.5rem;
}

.season-badge {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  padding: 0.2rem 0.7rem;
  border-radius: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.moon-count {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-left: 0.5rem;
}

.lives-display {
  color: var(--danger);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}
.lives-display.hidden { display: none; }

/* Stats row */
.stats-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1.2rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
}

.stat-pill .stat-label {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  width: 56px;
}

.stat-bar-bg {
  width: 60px;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent2);
  transition: width 0.3s ease;
}

.stat-pill .stat-val {
  color: var(--text);
  width: 24px;
  text-align: right;
}

/* Health bar */
.health-pill .stat-bar-fill { background: var(--good); }
.health-pill.low .stat-bar-fill { background: var(--danger); }

/* Body */
.game-body {
  display: grid;
  grid-template-columns: 1fr 380px;
  overflow: hidden;
}

/* Narrative */
.narrative-panel {
  padding: 1rem 1.2rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#narrative-log {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.log-entry {
  font-size: 0.95rem;
  padding: 0.45rem 0.8rem;
  border-radius: 4px;
  border-left: 3px solid transparent;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; } }

.log-entry.normal  { color: var(--text);     border-left-color: var(--border); }
.log-entry.good    { color: var(--good);     border-left-color: var(--good);   background: #1a2e20; }
.log-entry.danger  { color: var(--danger);   border-left-color: var(--danger); background: #2e1a1a; }
.log-entry.info    { color: var(--info);     border-left-color: transparent;   font-size: 0.82rem; font-family: var(--font-ui); }
.log-entry.system  { color: var(--accent);   border-left-color: var(--accent); font-style: italic; }

.log-divider {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 0.3rem 0;
  opacity: 0.5;
}

/* Action panel */
.action-panel {
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg2);
}

/* ── Cat portrait ─────────────────────────────────────────────────────── */
#cat-portrait {
  margin-bottom: 0.75rem;
}

.nest-card {
  background: radial-gradient(ellipse at bottom, #1e1409 0%, #110d05 100%);
  border: 1px solid #3a2910;
  border-radius: 10px;
  padding: 14px 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

/* Woven nest texture at the bottom */
.nest-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 28px;
  background: repeating-linear-gradient(
    -50deg,
    transparent, transparent 5px,
    rgba(90,55,15,0.35) 5px, rgba(90,55,15,0.35) 6px
  ),
  repeating-linear-gradient(
    50deg,
    transparent, transparent 5px,
    rgba(70,40,10,0.25) 5px, rgba(70,40,10,0.25) 6px
  );
  pointer-events: none;
}

/* Cat figure wrapper — scales with life stage */
.cat-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  transition: transform 0.5s ease;
}

/* The main cat body wrapper */
.cat-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}

/* 2D SVG cat */
.cat-svg {
  display: block;
  overflow: visible;
}

/* Small kit figures beside the main cat */
.kit-figure {
  display: flex;
  align-items: flex-end;
  transform: scale(0.45);
  transform-origin: bottom center;
  opacity: 0.85;
  margin-bottom: -14px;
}

/* Status badges row */
.portrait-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  min-height: 20px;
  position: relative;
  z-index: 1;
}

.p-badge {
  font-size: 0.72rem;
  font-family: var(--font-ui);
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid;
  letter-spacing: 0.04em;
}
.p-badge.injury  { color: #e06060; border-color: #803030; background: #2a1010; }
.p-badge.sick    { color: #7ec87e; border-color: #2a6030; background: #101a10; }
.p-badge.scar    { color: #8899bb; border-color: #334466; background: #10141e; }
.p-badge.kits    { color: #d4a04a; border-color: #6a4a10; background: #1e1608; }
.p-badge.leader  { color: #c8c040; border-color: #686010; background: #181600; }
.p-badge.medcat  { color: #5ec87a; border-color: #1e6030; background: #0a1810; }

/* ── Cat idle animations ──────────────────────────────────────────────── */
@keyframes catBreathe {
  0%, 100% { transform: scaleY(1)    scaleX(1); }
  50%       { transform: scaleY(1.07) scaleX(0.96); }
}
@keyframes tailSwish {
  0%, 100% { transform: rotate(0deg); }
  35%      { transform: rotate(-22deg); }
  70%      { transform: rotate(14deg); }
}
@keyframes earTwitchL {
  0%, 88%, 100% { transform: scaleY(1); }
  92%           { transform: scaleY(0.65) translateY(3px); }
}
@keyframes earTwitchR {
  0%, 80%, 100% { transform: scaleY(1); }
  84%           { transform: scaleY(0.65) translateY(3px); }
}
@keyframes catBlink {
  0%, 88%, 100% { opacity: 1; }
  92%           { opacity: 0.15; }
}

/* Apply animations to SVG elements */
.cat-svg-body {
  animation: catBreathe 3.8s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: 50% 50%;
}
.cat-svg-tail {
  animation: tailSwish 4.5s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: 0% 100%;
}
.cat-svg-ear-l {
  animation: earTwitchL 9s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: 50% 100%;
}
.cat-svg-ear-r {
  animation: earTwitchR 9s ease-in-out infinite 1.2s;
  transform-box: fill-box;
  transform-origin: 50% 100%;
}
.cat-svg-eyes { animation: catBlink 6s ease-in-out infinite; }

/* Sick — desaturate the whole SVG */
.cat-body.is-sick .cat-svg { filter: saturate(0.4) brightness(0.85); }

/* Injured — slight sway on the wrapper */
.cat-body.is-injured { animation: injuredSway 2.5s ease-in-out infinite; }
@keyframes injuredSway {
  0%,100% { transform: rotate(0deg) translateX(0); }
  30%     { transform: rotate(-2deg) translateX(-1px); }
  65%     { transform: rotate(1.5deg) translateX(1px); }
}

/* Leader — gold glow on the SVG head circle */
.cat-body.is-leader .cat-svg-head {
  filter: drop-shadow(0 0 10px rgba(220,200,60,0.5));
}

/* ── Relationships panel ──────────────────────────────────────────────── */
.relationships-panel {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 0.75rem;
}

.rel-heading {
  font-size: 0.72rem;
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.rel-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rel-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}

.rel-name {
  width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-family: var(--font);
}
.rel-name.is-mate { color: var(--accent); }
.rel-name.is-mate::before { content: '♥ '; font-size: 0.7rem; }

.rel-bar-bg {
  flex: 1;
  height: 5px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}
.rel-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent2);
  transition: width 0.4s ease;
}
.rel-bar-fill.mate { background: var(--accent); }

.rel-val {
  width: 22px;
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-ui);
}

/* ── Battle move buttons ──────────────────────────────────────────────── */
.battle-intro {
  font-style: italic;
  color: var(--danger);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--danger);
  padding-left: 0.6rem;
}

.move-btn {
  display: flex;
  flex-direction: column;
  background: #1a0f0f;
  border: 1px solid #5a2020;
  color: var(--text);
  padding: 0.55rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
  width: 100%;
  gap: 2px;
}
.move-btn:hover { background: #251010; border-color: var(--danger); }
.move-btn .move-name { font-family: var(--font); font-size: 0.95rem; }
.move-btn .move-stat { font-family: var(--font-ui); font-size: 0.72rem; color: var(--text-dim); }

#action-heading {
  font-size: 1rem;
  color: var(--text-dim);
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.action-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.95rem;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  width: 100%;
}
.action-btn:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }
.action-btn .icon { font-size: 1.1rem; }

/* Event box */
.event-box {
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 1rem;
  font-style: italic;
  color: var(--text-head);
  font-size: 0.95rem;
}
.event-box.hidden { display: none; }
.event-box h4 {
  font-size: 0.75rem;
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-style: normal;
}

/* Camp bar / tabs */
.camp-bar {
  display: flex;
  background: var(--bg2);
  border-top: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 0.6rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  cursor: pointer;
  border-top: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-top-color: var(--accent); }
.tab-btn.tab-end { flex: 0 0 auto; padding: 0.6rem 1rem; color: var(--text-dim); font-size: 0.8rem; border-left: 1px solid var(--border); }
.tab-btn.tab-end:hover { color: var(--danger); }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .game-body { grid-template-columns: 1fr; }
  .action-panel { border-top: 1px solid var(--border); }
}

/* ── Season themes ────────────────────────────────────────────────────── */
body.season-Newleaf    .cat-rank { color: #4caf6e; }
body.season-Greenleaf  .cat-rank { color: #c8a440; }
body.season-Leaf-fall  .cat-rank { color: #c47c2a; }
body.season-Leaf-bare  .cat-rank { color: #7ab0d0; }
