/* Korean Life Sim — Core Design System & Home Screen */
:root {
  --bg-0: #14100e;
  --bg-1: #1d1714;
  --surface-1: #251e1a;
  --surface-2: #2f2621;
  --surface-3: #3c312a;
  --glass: rgba(27, 21, 18, 0.86);
  --glass-strong: rgba(21, 16, 14, 0.94);
  --border-subtle: rgba(245, 232, 214, 0.10);
  --border-warm: rgba(245, 232, 214, 0.18);
  --border-strong: rgba(245, 232, 214, 0.28);
  --text-main: #f6efe6;
  --text-soft: #d5c6b4;
  --text-muted: #9f8f7e;
  --gold: #f5d7a8;
  --accent: #d88b44;
  --accent-hover: #e69d57;
  --accent-ink: #1e1208;
  --sage: #66a976;
  --sage-soft: rgba(102, 169, 118, 0.14);
  --danger: #dd5746;
  --danger-soft: rgba(221, 87, 70, 0.16);
  --paper: #f6f0e4;
  --paper-2: #ebe2d1;
  --paper-ink: #201a16;
  --paper-muted: #64584c;
  --paper-border: #d5c8b2;
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.50);
  --shadow-md: 0 10px 26px rgba(0, 0, 0, 0.36);
  --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.24);
  --font-sans: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background-color: var(--bg-0);
  background-image: radial-gradient(circle at 50% 0%, #261e19 0%, #14100e 72%);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  word-break: keep-all;
  overflow-wrap: break-word;
}
.hidden { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; }

/* Subtle scrollbars */
*::-webkit-scrollbar { width: 7px; height: 7px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(245, 232, 214, 0.18); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(245, 232, 214, 0.30); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 11px 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: linear-gradient(180deg, #df954f 0%, #c97f3a 100%);
  color: var(--accent-ink);
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #eaa35e 0%, #d58b45 100%);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.32);
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.48; cursor: default; box-shadow: none; }
.btn.small {
  min-height: 38px;
  padding: 7px 14px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 600;
}
.btn.tonal, .btn.quit {
  background: var(--surface-2);
  color: var(--text-soft);
  border: 1px solid var(--border-warm);
  box-shadow: none;
}
.btn.tonal:hover:not(:disabled), .btn.quit:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text-main);
  border-color: var(--border-strong);
}

.error {
  color: #ff9c89;
  background: var(--danger-soft);
  border: 1px solid rgba(221, 87, 70, 0.32);
  border-radius: 11px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.45;
  margin: 6px 0;
}
.note { color: var(--text-soft); font-size: 13.5px; line-height: 1.45; margin: 4px 0; }

/* Range Sliders */
.slider {
  color: var(--text-soft);
  font-size: 13.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 104px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg-1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg-1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

/* Custom Toggle Switches */
.practice, .ph-skip {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.35;
  cursor: pointer;
  user-select: none;
}
.practice input[type="checkbox"], .ph-skip input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  width: 38px;
  height: 22px;
  margin: 0;
  flex: none;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-warm);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.practice input[type="checkbox"]::after, .ph-skip input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-soft);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.18s ease, background 0.18s ease;
}
.practice input[type="checkbox"]:checked, .ph-skip input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent-hover);
}
.practice input[type="checkbox"]:checked::after, .ph-skip input[type="checkbox"]:checked::after {
  transform: translateX(16px);
  background: #fff9f0;
}

/* Game-stopped top alert (keepalive.js) & Quit screen */
.gamestopped {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 99999;
  padding: 12px 18px;
  background: #a82b22;
  border-bottom: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.quit-screen {
  max-width: 420px;
  margin: 18vh auto 0;
  padding: 28px 32px;
  background: var(--surface-1);
  border: 1px solid var(--border-warm);
  border-radius: 20px;
  color: var(--text-main);
  font-size: 17px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

/* Mini pill buttons & tappable Korean words (shared across Phone & Replay) */
.mini {
  background: var(--surface-2);
  color: var(--text-soft);
  border: 1px solid var(--border-warm);
  border-radius: 999px;
  padding: 5px 12px;
  min-height: 32px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.mini:hover:not(:disabled) { background: var(--surface-3); color: var(--text-main); border-color: var(--border-strong); }
.mini.on { background: rgba(221, 87, 70, 0.24); border-color: rgba(221, 87, 70, 0.55); color: #ffb5a8; }
.mini:disabled { cursor: default; opacity: 0.6; }

.kotext { font-size: 20px; line-height: 1.65; }
.w {
  cursor: pointer;
  border-bottom: 1.5px dashed rgba(245, 215, 168, 0.48);
  border-radius: 4px;
  padding: 1px 2px;
  margin: 0 -1px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.w:hover { background: rgba(245, 215, 168, 0.16); border-bottom-color: var(--gold); }

/* ---------------- HOME SCREEN & COMPANION BAR ---------------- */
#home {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 16px 36px;
}
@media (min-width: 880px) {
  #home {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 28px;
    padding: 20px 24px;
  }
  #home .card.gamebar { position: sticky; top: 20px; width: 350px; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  padding: 28px 32px;
  box-shadow: var(--shadow-lg);
}

/* Direct ?pack= Start card */
#directstart {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 410px;
  min-height: 220px;
  background: var(--surface-1);
  border: 1px solid var(--border-warm);
  border-radius: 28px;
  padding: 32px 24px;
  box-shadow: var(--shadow-lg);
}
#directstart .btn.place {
  width: 100%;
  min-height: 76px;
  font-size: 26px;
  border-radius: 18px;
  justify-content: center;
}

.card.gamebar {
  width: 100%;
  max-width: 410px;
  min-width: 0;
  padding: 20px 22px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.gb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}
#homemode {
  background: var(--surface-2);
  color: var(--gold);
  border: 1px solid var(--border-warm);
  box-shadow: none;
}
#homemode:hover { background: var(--surface-3); border-color: var(--accent); }

.settings { display: flex; flex-direction: column; gap: 12px; margin: 0; }
.gb-slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.20);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
}
.gb-slider-row .slider { width: 100%; justify-content: space-between; }
.gb-slider-row input[type="range"] { width: 130px; }

.gb-toggles {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 6px 12px;
}
.gb-toggles .practice {
  margin: 0;
  padding: 8px 2px;
  border-bottom: 1px solid rgba(245, 232, 214, 0.06);
}
.gb-toggles .practice:last-child { border-bottom: 0; }

.gb-alerts:empty { display: none; }
#syncbtns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
#talkline { color: var(--text-soft); font-size: 13.5px; }

.gb-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}
#desktopstate { margin: 0; font-size: 13px; color: var(--text-muted); flex: 1; min-width: 140px; }
#creditsline { margin: 0; }
#creditslink { color: var(--gold); text-decoration: none; font-size: 13px; }
#creditslink:hover { text-decoration: underline; }
.btn.quit { margin: 0; min-height: 36px; padding: 6px 14px; font-size: 13px; }

@media (max-width: 700px) {
  #home { padding: 10px 10px 28px; gap: 14px; }
  .card.gamebar { max-width: 100%; padding: 16px 14px; border-radius: 22px; }
  .btn.small, .mini { min-height: 40px; }
  .gb-slider-row input[type="range"] { width: 112px; }
}
