/* ==========================================================================
   SuomiMon – Kalevala-Saariston seikkailu
   Mobiili ensin, lasimaiset paneelit, revontulivärit.
   ========================================================================== */
:root {
  --bg: #070d18;
  --bg-2: #0c1626;
  --panel: rgba(13, 22, 38, 0.84);
  --panel-solid: #101b2e;
  --panel-2: rgba(22, 36, 58, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --text: #eaf2ff;
  --muted: #93a4bd;
  --mint: #7df2c8;
  --violet: #a98bff;
  --gold: #ffd23f;
  --loyly: #ff8a3d;
  --danger: #ff5a4f;
  --ok: #4fd97a;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --ui-font: "Segoe UI", "Trebuchet MS", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui-font);
  overscroll-behavior: none;
  user-select: none;
}

body { position: fixed; inset: 0; }

#app { position: absolute; inset: 0; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.screen { position: absolute; inset: 0; }
.hidden { display: none !important; }

button { font-family: inherit; color: inherit; cursor: pointer; }

/* --- yleiset napit ------------------------------------------------------- */
.btn {
  border: 1px solid var(--line-strong);
  background: rgba(20, 32, 52, 0.8);
  color: var(--text);
  padding: 0.85rem 1.5rem;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  backdrop-filter: blur(10px);
  transition: transform 0.12s ease, background 0.2s, border-color 0.2s;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, #ff8a3d, #ffcf5c);
  border-color: rgba(255, 255, 255, 0.5);
  color: #1b1206;
  box-shadow: 0 10px 30px rgba(255, 138, 61, 0.35);
}
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.icon-btn {
  width: 46px; height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 1.2rem;
  display: grid; place-items: center;
  transition: transform 0.12s ease, background 0.2s;
}
.icon-btn:active { transform: scale(0.92); background: var(--panel-2); }

/* --- lataus ------------------------------------------------------------- */
#loading {
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 30%, #16273f, #070d18 65%);
  z-index: 90;
}
.loading-inner { text-align: center; padding: 2rem; }
.loading-logo {
  font-size: clamp(2.4rem, 10vw, 4rem);
  font-weight: 900; letter-spacing: 0.08em;
  background: linear-gradient(120deg, #ffd23f, #ff8a3d 40%, #a98bff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.loading-logo span { color: #7df2c8; -webkit-text-fill-color: #7df2c8; }
.loading-bar {
  width: min(320px, 70vw); height: 4px; border-radius: 99px;
  background: rgba(255, 255, 255, 0.12); margin: 1.6rem auto 0.9rem; overflow: hidden;
}
.loading-bar span {
  display: block; height: 100%; width: 40%;
  background: linear-gradient(90deg, #7df2c8, #ffd23f);
  border-radius: 99px; animation: loadSlide 1.4s ease-in-out infinite;
}
@keyframes loadSlide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
#loading-text { color: var(--muted); font-size: 0.9rem; margin: 0; }

/* --- aloitusvalikko ----------------------------------------------------- */
#title-screen { z-index: 40; overflow: hidden; }
.title-vignette {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 50% 30%, rgba(7, 13, 24, 0.05), rgba(7, 13, 24, 0.75) 65%, #070d18 100%),
    linear-gradient(180deg, rgba(7, 13, 24, 0.1), rgba(7, 13, 24, 0.92));
}
.title-content {
  position: relative; z-index: 2;
  height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: calc(1.5rem + var(--safe-t)) 1.5rem calc(1.5rem + var(--safe-b));
  text-align: center;
}
.title-badge {
  display: inline-flex; align-items: center;
  padding: 0.35rem 0.9rem;
  border: 1px solid rgba(125, 242, 200, 0.4);
  border-radius: 999px;
  color: var(--mint);
  background: rgba(125, 242, 200, 0.08);
  font-size: 0.75rem; letter-spacing: 0.22em; text-transform: uppercase;
  margin-bottom: 0.8rem;
}
.title-logo {
  margin: 0;
  font-size: clamp(2.7rem, 13.2vw, 8rem);
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: 0.02em;
  background: linear-gradient(160deg, #fff7e0 10%, #ffd23f 35%, #ff8a3d 60%, #a98bff 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 14px 40px rgba(255, 138, 61, 0.35));
}
.title-logo span { color: transparent; -webkit-text-fill-color: transparent; }
.title-tagline {
  color: #c9d6e8; max-width: 32rem; line-height: 1.5;
  margin: 1rem 0 1.8rem; font-size: clamp(0.9rem, 3.6vw, 1.05rem);
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
}
.title-menu { display: flex; flex-direction: column; gap: 0.65rem; width: min(330px, 78vw); }
.title-menu .btn { width: 100%; }
.title-footer {
  position: absolute; bottom: calc(1rem + var(--safe-b)); left: 0; right: 0;
  display: flex; flex-direction: column; gap: 0.25rem;
  color: rgba(200, 215, 235, 0.5); font-size: 0.72rem;
  padding: 0 1rem;
}

/* --- HUD ---------------------------------------------------------------- */
#world-ui { pointer-events: none; z-index: 20; }
#world-ui > * { pointer-events: auto; }
.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: calc(0.65rem + var(--safe-t)) calc(0.65rem + var(--safe-r)) 0.5rem calc(0.65rem + var(--safe-l));
}
.zone-pill {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.85rem;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.zone-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 14px var(--mint);
}
.zone-pill strong { display: block; font-size: 0.85rem; line-height: 1.1; }
.zone-pill small { color: var(--muted); font-size: 0.68rem; }
.badge-row { display: flex; gap: 4px; flex-wrap: wrap; max-width: 150px; margin-top: 0.2rem; }
.badge-slot {
  width: 22px; height: 22px; border-radius: 7px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.7rem; opacity: 0.35;
  filter: grayscale(1);
}
.badge-slot.owned { opacity: 1; filter: none; background: rgba(255, 210, 63, 0.16); border-color: rgba(255, 210, 63, 0.5); }
.hud-right { margin-left: auto; display: flex; align-items: center; gap: 0.35rem; }
.money-chip {
  display: flex; align-items: center; gap: 0.3rem;
  padding: 0.4rem 0.65rem; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 0.8rem; color: var(--gold);
  backdrop-filter: blur(12px);
}
.money-chip span { opacity: 0.7; font-size: 0.68rem; }

.quest-chip {
  position: absolute; top: calc(4.4rem + var(--safe-t)); left: 50%;
  transform: translateX(-50%);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: rgba(10, 18, 32, 0.75);
  border: 1px solid rgba(255, 210, 63, 0.3);
  color: #ffe6a0; font-size: 0.75rem;
  white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
  backdrop-filter: blur(10px);
  transition: opacity 0.4s;
}
.quest-chip:empty { display: none; }

.hud-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 0 calc(1rem + var(--safe-r)) calc(1.1rem + var(--safe-b)) calc(1rem + var(--safe-l));
  display: flex; align-items: flex-end; justify-content: space-between;
  pointer-events: none;
}
.joystick {
  width: 132px; height: 132px;
  border-radius: 50%;
  background: rgba(12, 20, 34, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  position: relative;
  touch-action: none;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}
.joystick-ring {
  position: absolute; inset: 22px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.14);
}
.joystick-knob {
  position: absolute; width: 54px; height: 54px;
  left: 50%; top: 50%;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #eaf6ff, #8fb6d9 55%, #4a6b8c);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45), inset 0 -3px 8px rgba(0, 0, 0, 0.25);
  transition: transform 0.05s linear;
}
.hud-actions { display: flex; align-items: flex-end; gap: 0.8rem; pointer-events: auto; }
.interact-btn {
  width: 88px; height: 88px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: linear-gradient(150deg, rgba(255, 138, 61, 0.95), rgba(255, 85, 40, 0.95));
  color: #1b1206;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(255, 110, 50, 0.35);
  transition: transform 0.1s;
}
.interact-btn:active { transform: scale(0.94); }
.interact-icon { font-size: 1.5rem; line-height: 1; }
.interact-label { font-size: 0.7rem; letter-spacing: 0.04em; }
.hint {
  position: absolute; left: 50%; bottom: calc(9.4rem + var(--safe-b));
  transform: translateX(-50%);
  color: rgba(234, 242, 255, 0.75);
  background: rgba(8, 14, 24, 0.65);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.75rem;
  opacity: 0; transition: opacity 0.3s;
  pointer-events: none; white-space: nowrap;
}
.hint.show { opacity: 1; }

/* --- dialogi ------------------------------------------------------------ */
.dialogue {
  position: absolute; left: 0; right: 0; bottom: 0;
  z-index: 60;
  padding: 0 0 calc(0.9rem + var(--safe-b));
  display: flex; justify-content: center;
  pointer-events: none;
}
.dialogue-inner {
  pointer-events: auto;
  width: min(880px, 94vw);
  display: flex; gap: 0.9rem;
  padding: 0.9rem;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(16, 27, 46, 0.96), rgba(10, 18, 32, 0.98));
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  animation: riseIn 0.25s ease;
}
@keyframes riseIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.dialogue-portrait {
  width: 96px; height: 96px; flex: 0 0 auto;
  border-radius: 16px; overflow: hidden;
  background: #0b1424;
  border: 1px solid var(--line);
}
.dialogue-portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dialogue-body { position: relative; flex: 1; min-width: 0; }
.dialogue-name {
  font-weight: 800; color: var(--gold);
  font-size: 0.86rem; letter-spacing: 0.03em; margin-bottom: 0.2rem;
}
.dialogue-text {
  margin: 0; font-size: clamp(0.9rem, 3.6vw, 1rem); line-height: 1.55;
  color: #e6eefb; min-height: 3.1em; padding-right: 2rem;
}
.dialogue-next {
  position: absolute; right: 0.2rem; bottom: 0.1rem;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--mint); font-size: 0.9rem;
  animation: bob 1.2s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

/* --- taistelu ----------------------------------------------------------- */
#battle-screen {
  z-index: 50;
  display: flex; flex-direction: column;
  pointer-events: none;
  padding: calc(0.5rem + var(--safe-t)) 0 calc(0.5rem + var(--safe-b));
}
#battle-screen > * { pointer-events: auto; }
#battle-screen::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(7, 13, 24, 0.35), transparent 30%, transparent 58%, rgba(7, 13, 24, 0.75));
  pointer-events: none;
}
.battle-head {
  position: relative; z-index: 2;
  display: flex; flex-direction: column;
  gap: 0.5rem;
  padding: 0 0.6rem;
}
.combatant {
  display: flex; gap: 0.6rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(16, 27, 46, 0.94), rgba(12, 20, 34, 0.86));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  width: min(360px, 92vw);
  transition: opacity 0.2s;
}
.combatant.foe { align-self: flex-end; }
.combatant.player { align-self: flex-start; margin-top: 0.1rem; }
.combatant-portrait {
  width: 66px; height: 66px; border-radius: 12px;
  object-fit: cover; background: #0a1322;
  border: 1px solid var(--line);
}
.combatant-info { flex: 1; min-width: 0; }
.combatant-line { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.combatant-name { font-weight: 800; font-size: 0.95rem; letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combatant-lvl { color: var(--muted); font-size: 0.74rem; font-weight: 700; }
.type-row { display: flex; gap: 3px; margin: 0.18rem 0 0.3rem; flex-wrap: wrap; }
.type-chip {
  font-size: 0.62rem; font-weight: 700;
  padding: 0.12rem 0.4rem; border-radius: 999px;
  color: #0b1220; letter-spacing: 0.03em;
  text-transform: uppercase;
}
.hp-shell {
  height: 9px; border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.hp-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #38c96a, #6ef29a);
  border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;
}
.hp-fill.mid { background: linear-gradient(90deg, #e8a52a, #ffd23f); }
.hp-fill.low { background: linear-gradient(90deg, #e0382a, #ff6a4a); }
.hp-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.68rem; color: var(--muted); margin-top: 0.18rem; height: 1.1em;
}
.status-chip {
  font-size: 0.6rem; font-weight: 800;
  padding: 0.1rem 0.4rem; border-radius: 6px;
  background: rgba(255, 90, 79, 0.2);
  color: #ff9c90; border: 1px solid rgba(255, 90, 79, 0.35);
  text-transform: uppercase;
}
.xp-shell {
  height: 4px; border-radius: 99px; margin-top: 0.28rem;
  background: rgba(255, 255, 255, 0.08); overflow: hidden;
}
.xp-fill { height: 100%; width: 0; background: linear-gradient(90deg, #6b8fff, #a98bff); transition: width 0.4s; }
.battle-center {
  position: static;
  display: flex; flex-wrap: wrap; flex-direction: row; align-items: center; justify-content: center;
  gap: 0.4rem;
  margin: -0.1rem 0;
  pointer-events: none;
  min-height: 1.4rem;
}
.weather-badge {
  display: flex; align-items: center; gap: 0.3rem;
  font-size: 0.68rem; font-weight: 700;
  padding: 0.28rem 0.6rem; border-radius: 999px;
  background: rgba(10, 18, 32, 0.8);
  border: 1px solid var(--line);
  color: #dbe8ff;
  backdrop-filter: blur(8px);
  white-space: nowrap;
}
.party-dots { display: flex; gap: 3px; }
.party-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  display: block;
}
.party-dots i.dead { background: rgba(255, 90, 79, 0.35); }
.party-dots i.active { background: var(--gold); box-shadow: 0 0 8px var(--gold); }

.battle-log {
  position: relative; z-index: 2;
  margin: auto 0 0.6rem;
  align-self: center;
  width: min(620px, 92vw);
  min-height: 3rem;
  display: grid; place-items: center;
  padding: 0.5rem 1rem;
  border-radius: 14px;
  background: rgba(8, 14, 24, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  text-align: center;
}
.battle-log p { margin: 0; font-size: 0.88rem; line-height: 1.4; color: #eaf2ff; }
.battle-log p[data-tone="good"] { color: #9af7c4; }
.battle-log p[data-tone="bad"] { color: #ffb0a6; }
.battle-log p[data-tone="great"] { color: var(--gold); font-weight: 700; }
.battle-log p[data-tone="weather"] { color: #b9e8ff; }

.battle-controls {
  position: relative; z-index: 3;
  padding: 0 0.6rem;
  display: grid;
  gap: 0.45rem;
}
.sisu-wrap {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  border-radius: 12px;
  background: rgba(12, 20, 34, 0.7);
  border: 1px solid var(--line);
}
.sisu-label { font-size: 0.66rem; color: var(--muted); display: flex; gap: 0.3rem; white-space: nowrap; }
.sisu-label b { color: var(--gold); }
.sisu-track { flex: 1; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.sisu-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #ffd23f, #ff8a3d, #ff4a4a);
  transition: width 0.35s ease;
}
.sisu-btn {
  border: 1px solid rgba(255, 210, 63, 0.45);
  background: rgba(255, 210, 63, 0.12);
  color: var(--gold);
  border-radius: 10px;
  padding: 0.35rem 0.6rem;
  font-size: 0.66rem; font-weight: 900; letter-spacing: 0.06em;
}
.sisu-btn:not(:disabled) { animation: sisuGlow 1.2s ease-in-out infinite; }
@keyframes sisuGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 210, 63, 0); }
  50% { box-shadow: 0 0 18px rgba(255, 210, 63, 0.5); }
}
.moves-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.move-btn {
  position: relative;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 0.55rem 0.7rem;
  text-align: left;
  background: linear-gradient(135deg, rgba(25, 40, 64, 0.95), rgba(15, 25, 42, 0.95));
  overflow: hidden;
  transition: transform 0.1s;
  min-height: 62px;
}
.move-btn:active { transform: scale(0.97); }
.move-btn::before {
  content: ""; position: absolute; inset: 0;
  background: var(--type-color, #4a5a7a);
  opacity: 0.22;
}
.move-btn .mv-name { position: relative; display: block; font-weight: 800; font-size: 0.84rem; margin-bottom: 0.12rem; }
.move-btn .mv-meta { position: relative; display: flex; gap: 0.4rem; align-items: center; font-size: 0.64rem; color: #cfd9e8; }
.move-btn .mv-pp { margin-left: auto; color: var(--muted); }
.move-btn .mv-type { padding: 0.05rem 0.35rem; border-radius: 99px; background: var(--type-color); color: #08101c; font-weight: 800; font-size: 0.58rem; text-transform: uppercase; }
.move-btn .mv-cat { opacity: 0.75; }
.move-btn:disabled { opacity: 0.4; }
.move-btn.ultimate { border-color: rgba(255, 210, 63, 0.4); }
.move-btn.ultimate::after {
  content: "★"; position: absolute; top: 4px; right: 6px; color: var(--gold); font-size: 0.7rem;
}
.battle-action-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }
.act-btn {
  border: 1px solid var(--line);
  background: rgba(16, 27, 46, 0.9);
  border-radius: 12px;
  padding: 0.5rem 0.25rem;
  font-size: 0.72rem; font-weight: 700;
  min-height: 42px;
}
.act-btn:active { background: rgba(40, 60, 90, 0.9); }

.battle-submenu {
  position: absolute; inset: auto 0 0 0;
  z-index: 20;
  background: linear-gradient(180deg, rgba(12, 20, 34, 0.98), rgba(8, 14, 24, 0.99));
  border-top: 1px solid var(--line-strong);
  border-radius: 20px 20px 0 0;
  padding: 0.9rem 1rem calc(1rem + var(--safe-b));
  max-height: 72%;
  display: flex; flex-direction: column;
  animation: riseIn 0.2s ease;
}
.submenu-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.submenu-head h3 { margin: 0; font-size: 1rem; }
.submenu-body { overflow-y: auto; display: grid; gap: 0.5rem; }
.sub-menu-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.55rem 0.7rem; border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(20, 33, 54, 0.8);
  text-align: left;
}
.sub-menu-item:active { background: rgba(35, 52, 80, 0.9); }
.sub-menu-item img { width: 42px; height: 42px; border-radius: 9px; object-fit: cover; }
.sub-menu-item .smi-name { font-weight: 700; font-size: 0.86rem; }
.sub-menu-item .smi-sub { font-size: 0.7rem; color: var(--muted); }
.sub-menu-item .smi-right { margin-left: auto; text-align: right; font-size: 0.72rem; color: var(--muted); }
.sub-menu-item:disabled { opacity: 0.4; }

/* --- paneelit ----------------------------------------------------------- */
.panel-layer {
  position: absolute; inset: 0; z-index: 70;
  background: rgba(4, 8, 15, 0.6);
  backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center;
}
.panel-sheet {
  width: min(980px, 100%);
  max-height: 94%;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, rgba(17, 29, 49, 0.99), rgba(9, 16, 28, 0.99));
  border: 1px solid var(--line-strong);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  animation: sheetUp 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0.4; } to { transform: translateY(0); opacity: 1; } }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1rem calc(0.6rem + var(--safe-t) * 0);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.panel-head h2 { margin: 0; font-size: 1.05rem; letter-spacing: 0.02em; }
.panel-body {
  overflow-y: auto; padding: 0.9rem 1rem calc(1.2rem + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}
.panel-section { margin-bottom: 1.1rem; }
.panel-section h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 0 0 0.55rem; }
.panel-note { color: var(--muted); font-size: 0.78rem; line-height: 1.5; }

/* Tiimi */
.party-grid { display: grid; gap: 0.55rem; }
.party-card {
  display: flex; gap: 0.7rem; align-items: center;
  padding: 0.6rem; border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(24, 39, 62, 0.9), rgba(14, 24, 40, 0.9));
  text-align: left;
}
.party-card.active { border-color: rgba(255, 210, 63, 0.5); }
.party-card.fainted { opacity: 0.55; }
.party-card img { width: 58px; height: 58px; border-radius: 11px; object-fit: cover; }
.party-card .pc-main { flex: 1; min-width: 0; }
.party-card .pc-name { font-weight: 800; font-size: 0.9rem; display: flex; gap: 0.4rem; align-items: baseline; }
.party-card .pc-name small { color: var(--muted); font-weight: 600; }
.party-card .pc-hp { margin-top: 0.3rem; }
.party-card .pc-hp-text { font-size: 0.68rem; color: var(--muted); margin-top: 0.15rem; display: flex; justify-content: space-between; }
.pc-badge { font-size: 0.62rem; padding: 0.1rem 0.35rem; border-radius: 6px; background: rgba(255, 90, 79, 0.2); color: #ff9c90; }
.pc-actions { display: flex; flex-direction: column; gap: 0.3rem; }
.mini-btn {
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06);
  border-radius: 9px; padding: 0.3rem 0.5rem; font-size: 0.66rem; color: var(--text);
}
.mini-btn:active { background: rgba(255, 255, 255, 0.14); }

/* Dex */
.dex-top { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.8rem; flex-wrap: wrap; }
.dex-progress { flex: 1; min-width: 150px; }
.dex-progress .bar { height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin-top: 0.3rem; }
.dex-progress .bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--mint), var(--gold)); }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 0.5rem; }
.dex-card {
  position: relative; overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(20, 33, 54, 0.8);
  padding: 0.35rem;
  text-align: center;
}
.dex-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: #0a1322; }
.dex-card .dx-no { position: absolute; top: 6px; left: 8px; font-size: 0.6rem; color: rgba(255,255,255,0.65); font-weight: 700; }
.dex-card .dx-name { font-size: 0.68rem; font-weight: 700; margin-top: 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex-card.locked { opacity: 0.55; }
.dex-card.locked img { filter: brightness(0) saturate(0) opacity(0.5); }
.dex-card.caught { border-color: rgba(125, 242, 200, 0.4); }
.dex-card .dx-check { position: absolute; top: 6px; right: 8px; color: var(--mint); font-size: 0.7rem; }
.dex-detail { display: grid; gap: 0.8rem; }
.dex-hero { display: flex; gap: 0.8rem; align-items: center; }
.dex-hero img { width: 120px; height: 120px; border-radius: 16px; object-fit: cover; }
.dex-hero .dh-name { font-size: 1.25rem; font-weight: 900; }
.dex-hero .dh-sub { color: var(--muted); font-size: 0.75rem; margin-top: 0.1rem; }
.stat-bars { display: grid; gap: 0.35rem; }
.stat-row { display: grid; grid-template-columns: 74px 1fr 32px; align-items: center; gap: 0.5rem; font-size: 0.7rem; color: var(--muted); }
.stat-row .bar { height: 7px; border-radius: 99px; background: rgba(255,255,255,0.1); overflow: hidden; }
.stat-row .bar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--mint), var(--gold)); }
.stat-row b { color: var(--text); font-size: 0.7rem; text-align: right; }
.ability-box, .move-box {
  padding: 0.6rem 0.7rem; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(20, 33, 54, 0.7); font-size: 0.76rem; line-height: 1.45;
}
.ability-box b, .move-box b { color: var(--gold); }
.moves-list { display: grid; gap: 0.4rem; }
.move-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.55rem; border-radius: 10px; background: rgba(255,255,255,0.04); font-size: 0.74rem; }
.move-row .type-dot { width: 8px; height: 8px; border-radius: 50%; }
.move-row .mr-name { font-weight: 700; }
.move-row .mr-meta { margin-left: auto; color: var(--muted); font-size: 0.66rem; white-space: nowrap; }
.evo-chain { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-size: 0.74rem; color: var(--muted); }
.evo-chain img { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; }

/* Reppu */
.bag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.55rem; }
.bag-item {
  display: flex; gap: 0.6rem; align-items: center;
  padding: 0.6rem; border-radius: 13px; border: 1px solid var(--line);
  background: rgba(20, 33, 54, 0.8); text-align: left;
}
.bag-item .bi-icon { font-size: 1.5rem; }
.bag-item .bi-name { font-weight: 700; font-size: 0.8rem; }
.bag-item .bi-count { margin-left: auto; font-weight: 800; color: var(--gold); font-size: 0.8rem; }
.bag-item .bi-desc { font-size: 0.64rem; color: var(--muted); margin-top: 0.1rem; line-height: 1.3; }
.bag-item:disabled { opacity: 0.4; }

/* Kartta */
.zone-map { display: grid; gap: 0.55rem; }
.zone-row {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem; border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(20, 33, 54, 0.8);
  text-align: left;
}
.zone-row.current { border-color: rgba(255, 210, 63, 0.55); background: rgba(255, 210, 63, 0.08); }
.zone-row.locked { opacity: 0.45; }
.zone-row .zr-index { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(255,255,255,0.08); font-weight: 800; font-size: 0.8rem; }
.zone-row .zr-name { font-weight: 800; font-size: 0.86rem; }
.zone-row .zr-sub { color: var(--muted); font-size: 0.68rem; }
.zone-row .zr-right { margin-left: auto; font-size: 0.7rem; color: var(--muted); text-align: right; }

/* Asetukset */
.settings-grid { display: grid; gap: 0.7rem; }
.setting-row { display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem; border-radius: 13px; border: 1px solid var(--line); background: rgba(20, 33, 54, 0.7); }
.setting-row .sr-label { flex: 1; font-size: 0.8rem; }
.setting-row .sr-label small { display: block; color: var(--muted); font-size: 0.68rem; margin-top: 0.15rem; line-height: 1.35; }
.toggle {
  width: 48px; height: 27px; border-radius: 99px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.12); position: relative; flex: 0 0 auto;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 21px; height: 21px; border-radius: 50%;
  background: #c9d6e8; transition: transform 0.2s, background 0.2s;
}
.toggle.on { background: rgba(125, 242, 200, 0.28); border-color: rgba(125, 242, 200, 0.5); }
.toggle.on::after { transform: translateX(21px); background: var(--mint); }
.field { display: grid; gap: 0.25rem; }
.field label { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.04em; }
.field input {
  width: 100%; padding: 0.6rem 0.7rem; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(8, 14, 24, 0.9);
  color: var(--text); font-size: 0.8rem; font-family: inherit;
}
.field input:focus { outline: none; border-color: rgba(125, 242, 200, 0.6); }
.status-line { font-size: 0.72rem; color: var(--muted); display: flex; gap: 0.5rem; align-items: center; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-dot.warn { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.status-dot.err { background: var(--danger); }

/* Kauppa */
.shop-grid { display: grid; gap: 0.5rem; }
.shop-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem; border-radius: 12px; border: 1px solid var(--line); background: rgba(20, 33, 54, 0.8); }
.shop-row .bi-icon { font-size: 1.3rem; }
.shop-row .sr-name { font-weight: 700; font-size: 0.8rem; }
.shop-row .sr-desc { font-size: 0.64rem; color: var(--muted); }
.shop-row .sr-buy { margin-left: auto; }

/* Aloitushirviövalinta */
.starter-grid { display: grid; gap: 0.7rem; }
.starter-card {
  display: flex; gap: 0.8rem; align-items: center;
  padding: 0.8rem; border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(26, 44, 70, 0.95), rgba(14, 24, 40, 0.95));
  text-align: left;
}
.starter-card:active { border-color: var(--gold); }
.starter-card img { width: 84px; height: 84px; border-radius: 14px; object-fit: cover; }
.starter-card .sc-name { font-size: 1rem; font-weight: 900; }
.starter-card .sc-desc { font-size: 0.72rem; color: var(--muted); line-height: 1.4; margin-top: 0.2rem; }

/* Loppu */
#ending-screen {
  z-index: 80; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 30%, rgba(255, 210, 63, 0.14), rgba(7, 13, 24, 0.96) 65%);
  padding: 1rem;
}
.ending-card {
  text-align: center; max-width: 520px; position: relative;
  padding: 2rem 1.5rem;
  border-radius: 24px;
  border: 1px solid rgba(255, 210, 63, 0.3);
  background: rgba(10, 18, 30, 0.9);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.ending-sun {
  width: 80px; height: 80px; margin: 0 auto 1rem; border-radius: 50%;
  background: radial-gradient(circle, #fff3c4, #ffd23f 45%, rgba(255, 138, 61, 0.1) 70%);
  box-shadow: 0 0 60px rgba(255, 210, 63, 0.45);
}
.ending-card h1 { font-size: 2rem; margin: 0 0 0.6rem; color: var(--gold); }
.ending-card p { color: #cfd9e8; line-height: 1.6; font-size: 0.9rem; }
.ending-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin: 1.2rem 0; }
.ending-stats div { padding: 0.6rem; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); font-size: 0.75rem; }
.ending-stats b { display: block; font-size: 1.2rem; color: var(--mint); }
.ending-actions { display: grid; gap: 0.5rem; }

/* Toast + fade */
.toast-layer {
  position: absolute; top: calc(1rem + var(--safe-t)); left: 0; right: 0;
  z-index: 85; display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  pointer-events: none;
}
.toast {
  padding: 0.55rem 1rem; border-radius: 999px;
  background: rgba(12, 22, 38, 0.95);
  border: 1px solid var(--line-strong);
  font-size: 0.8rem; color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease, toastOut 0.3s ease 2.2s forwards;
  max-width: 90vw;
}
.toast.gold { border-color: rgba(255, 210, 63, 0.6); color: var(--gold); }
.toast.mint { border-color: rgba(125, 242, 200, 0.6); color: var(--mint); }
@keyframes toastIn { from { transform: translateY(-10px); opacity: 0; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }
.fade {
  position: absolute; inset: 0; z-index: 75;
  background: #05090f; opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease;
}
.fade.show { opacity: 1; pointer-events: auto; }

/* Vaakataso / työpöytä */
@media (min-width: 900px) {
  .battle-head { padding: 0 2rem; }
  .combatant { width: 400px; }
  .combatant-portrait { width: 78px; height: 78px; }
  .battle-controls { width: min(760px, 92vw); margin: 0 auto; }
  .battle-log { margin-bottom: 0.9rem; }
  .moves-grid { gap: 0.55rem; }
  .move-btn { padding: 0.7rem 0.9rem; }
  .panel-sheet { border-radius: 22px; margin-bottom: 2rem; max-height: 88%; }
  .panel-layer { align-items: center; }
  .hud-bottom { padding-left: 3rem; padding-right: 3rem; }
}

@media (max-height: 640px) and (orientation: landscape) {
  .battle-head { flex-direction: row; align-items: flex-start; }
  .combatant { width: 300px; }
  .combatant.player { margin-top: 5.5rem; }
  .combatant-portrait { width: 52px; height: 52px; }
  .battle-log { min-height: 2.2rem; margin-bottom: 0.35rem; }
  .battle-controls { gap: 0.3rem; }
  .move-btn { min-height: 54px; padding: 0.4rem 0.6rem; }
  .sisu-wrap { padding: 0.2rem 0.5rem; }
  .hud-top { padding-top: calc(0.4rem + var(--safe-t)); }
  .joystick { width: 104px; height: 104px; }
  .interact-btn { width: 72px; height: 72px; }
}

@media (max-width: 420px) {
  .zone-pill small { display: none; }
  .hud-right .icon-btn { width: 40px; height: 40px; font-size: 1rem; }
  .combatant { width: 100%; }
  .combatant-portrait { width: 54px; height: 54px; }
  .battle-log { width: 96vw; }
  .dialogue-portrait { width: 74px; height: 74px; }
  .dialogue-text { min-height: 3.6em; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* Vierityspalkit */
.panel-body::-webkit-scrollbar, .submenu-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-thumb, .submenu-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 99px; }

/* Pienet puhelimet: HUD mahtuu yhdelle riville */
@media (max-width: 560px) {
  .badge-row { display: none; }
  .hud-right { gap: 3px; }
  .hud-right .icon-btn { width: 40px; height: 40px; border-radius: 12px; font-size: 1.02rem; }
  .zone-pill { padding: 0.45rem 0.7rem; }
  .money-chip { padding: 0.35rem 0.5rem; font-size: 0.72rem; }
  .quest-chip { top: calc(3.9rem + var(--safe-t)); font-size: 0.7rem; }
}
@media (max-width: 410px) {
  .money-chip { display: none; }
}