/* ============================================================
   SIEGE BUDDIES — core styles: palette, typography, panels, buttons
   ============================================================ */
:root {
  --wood-hi:   #c07f42;
  --wood:      #a9682f;
  --wood-mid:  #8a4f21;
  --wood-dark: #5d3413;
  --outline:   #2f1d0c;
  --gold:      #ffc12e;
  --gold-mid:  #f0a418;
  --gold-dark: #a86a10;
  --blue:      #2f9be8;
  --blue-mid:  #1c72c4;
  --blue-dark: #14549a;
  --red:       #e84433;
  --red-mid:   #c22c1e;
  --red-dark:  #8f1f16;
  --green:     #6fc541;
  --green-mid: #4d9c2a;
  --cream:     #fff3d9;
  --cream-dim: #ecd9b4;
  --ink:       #2f1d0c;
  --sky:       #8fd0ff;
  --panel-shadow: 0 8px 0 rgba(0,0,0,.28), 0 14px 30px rgba(0,0,0,.35);
  --focus-ring: 0 0 0 4px #ffe89a, 0 0 0 7px #b8741a;
  --font-display: "Baloo 2", "Fredoka", "Segoe UI", system-ui, sans-serif;
  --font-body: "Fredoka", "Baloo 2", "Segoe UI", system-ui, sans-serif;
  --ui-scale: 1;
  --text-scale: 1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  font-size: calc(16px * var(--text-scale));
  color: var(--cream);
  background: #1b2a3d;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
img { -webkit-user-drag: none; }
button, input, select { font: inherit; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; font-size: calc(1rem * var(--ui-scale)); }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  background:
    radial-gradient(1200px 500px at 50% -80px, rgba(255,255,255,.10), transparent 60%),
    linear-gradient(180deg, #35597e 0%, #274363 55%, #1b2f47 100%);
  animation: none;
}
.screen.active { display: flex; }
.screen.anim-in { animation: screenIn .28s ease-out; }
@keyframes screenIn { from { opacity: 0; transform: scale(1.02); } to { opacity: 1; transform: none; } }
body.reduced-motion .screen.anim-in { animation: none; }

.screen-head {
  width: 100%;
  display: flex; align-items: center; justify-content: center;
  gap: 14px; padding: 16px 20px 6px;
  position: relative;
  flex: 0 0 auto;
}
.screen-head .back { position: absolute; left: 18px; top: 14px; }
.screen-head .corner { position: absolute; right: 18px; top: 18px; }

/* ---------- banner title (fabric ribbon) ---------- */
.banner-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: calc(1.9rem * var(--text-scale));
  letter-spacing: .5px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.35);
  background: linear-gradient(180deg, var(--red) 0%, var(--red-mid) 70%, var(--red-dark) 100%);
  border: 3px solid var(--outline);
  border-radius: 10px;
  padding: 8px 36px 10px;
  position: relative;
  box-shadow: 0 5px 0 rgba(0,0,0,.25);
}
.banner-title::before, .banner-title::after {
  content: ""; position: absolute; top: 12%; width: 26px; height: 76%;
  background: linear-gradient(180deg, var(--red-mid), var(--red-dark));
  border: 3px solid var(--outline); z-index: -1;
}
.banner-title::before { left: -20px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 42% 50%); }
.banner-title::after { right: -20px; clip-path: polygon(0 0, 100% 0, 58% 50%, 100% 100%, 0 100%); }

/* ---------- wooden panels ---------- */
.panel.wood {
  background:
    radial-gradient(circle at 12px 12px, #3c2410 5px, transparent 6px),
    radial-gradient(circle at calc(100% - 12px) 12px, #3c2410 5px, transparent 6px),
    radial-gradient(circle at 12px calc(100% - 12px), #3c2410 5px, transparent 6px),
    radial-gradient(circle at calc(100% - 12px) calc(100% - 12px), #3c2410 5px, transparent 6px),
    repeating-linear-gradient(180deg, transparent 0 44px, rgba(0,0,0,.10) 44px 47px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.045) 0 3px, transparent 3px 34px),
    linear-gradient(180deg, var(--wood-hi) 0%, var(--wood) 30%, var(--wood-mid) 100%);
  border: 4px solid var(--outline);
  border-radius: 14px;
  box-shadow: var(--panel-shadow), inset 0 2px 0 rgba(255,255,255,.22);
  color: var(--cream);
}
.panel.pad { padding: 16px 18px; }
.panel-title {
  font-family: var(--font-display); font-weight: 800;
  font-size: calc(1.15rem * var(--text-scale));
  margin-bottom: 8px; color: #ffe9bd;
  text-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.blue-text { color: #9fd4ff; } .red-text { color: #ffb4a8; } .gold-text { color: var(--gold); }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-display); font-weight: 800;
  font-size: calc(1rem * var(--text-scale));
  color: var(--cream);
  background: linear-gradient(180deg, var(--wood-hi), var(--wood-mid));
  border: 3px solid var(--outline);
  border-radius: 12px;
  padding: 9px 20px 11px;
  cursor: pointer;
  box-shadow: 0 5px 0 #241505, inset 0 2px 0 rgba(255,255,255,.25);
  text-shadow: 0 2px 0 rgba(0,0,0,.3);
  transition: transform .07s ease, box-shadow .07s ease, filter .12s ease;
  position: relative;
}
.btn:hover { filter: brightness(1.12); transform: translateY(-1px); box-shadow: 0 6px 0 #241505, inset 0 2px 0 rgba(255,255,255,.25); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #241505; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring), 0 5px 0 #241505; z-index: 2; }
.btn:disabled { filter: saturate(.35) brightness(.75); cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(180deg, #ffd35c, var(--gold-mid) 55%, #d88a10); color: #5a3505; text-shadow: 0 1px 0 rgba(255,255,255,.45); }
.btn.blue { background: linear-gradient(180deg, #57b4f5, var(--blue-mid)); }
.btn.red { background: linear-gradient(180deg, #f2695a, var(--red-mid)); }
.btn.gold { background: linear-gradient(180deg, #ffd35c, var(--gold-mid) 60%, #d88a10); color: #5a3505; text-shadow: 0 1px 0 rgba(255,255,255,.45); }
.btn.green { background: linear-gradient(180deg, #8bd95f, var(--green-mid)); }
.btn.big { font-size: calc(1.35rem * var(--text-scale)); padding: 13px 34px 16px; border-radius: 16px; }
.btn.small { font-size: calc(.85rem * var(--text-scale)); padding: 5px 12px 7px; box-shadow: 0 3px 0 #241505; }
.btn.small:active { transform: translateY(2px); box-shadow: 0 1px 0 #241505; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.ghosted { opacity: .82; }
.btn.back { font-size: 1.2rem; padding: 6px 14px 8px; }
.btn.danger { background: linear-gradient(180deg, #f2695a, var(--red-dark)); }

/* shield-shaped button (play etc.) */
.btn.shield {
  clip-path: polygon(0 0, 100% 0, 100% 62%, 50% 100%, 0 62%);
  border-radius: 10px 10px 0 0; padding-bottom: 26px;
}

/* ---------- inputs ---------- */
.text-input, .select-input {
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--outline);
  border-radius: 10px;
  padding: 8px 12px;
  width: 100%;
  font-weight: 600;
  box-shadow: inset 0 3px 0 rgba(0,0,0,.12);
}
.text-input:focus, .select-input:focus { outline: none; box-shadow: var(--focus-ring), inset 0 3px 0 rgba(0,0,0,.12); }
.code-input { text-transform: uppercase; letter-spacing: .5em; text-align: center; font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; }
.select-input { width: auto; padding: 6px 10px; }
.field-label { display: block; font-weight: 700; margin: 2px 0 6px; }

input[type="range"].slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 12px; border-radius: 8px;
  background: linear-gradient(180deg, #4a2f13, #6d451c);
  border: 2px solid var(--outline);
  cursor: pointer;
}
input[type="range"].slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe08a, var(--gold-mid) 60%, var(--gold-dark));
  border: 3px solid var(--outline);
  box-shadow: 0 2px 0 rgba(0,0,0,.3);
}
input[type="range"].slider:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.toggle-row { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.toggle-row:focus-within { box-shadow: var(--focus-ring); }
.toggle-row input[type="checkbox"] {
  appearance: none; width: 26px; height: 26px; border-radius: 8px;
  border: 3px solid var(--outline); background: var(--cream); cursor: pointer; position: relative; flex: 0 0 auto;
}
.toggle-row input[type="checkbox"]:checked { background: var(--green); }
.toggle-row input[type="checkbox"]:checked::after {
  content: "✔"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-weight: 900; font-size: 16px; text-shadow: 0 1px 0 rgba(0,0,0,.4);
}

/* ---------- layout utils ---------- */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap { gap: 12px; } .grow { flex: 1; } .wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.center { justify-content: center; }
.center-text { text-align: center; }
.scroll-area { flex: 1; width: min(1060px, 94%); overflow-y: auto; padding: 12px 6px 30px; scrollbar-width: thin; }
.scroll-area::-webkit-scrollbar { width: 12px; }
.scroll-area::-webkit-scrollbar-thumb { background: var(--wood-mid); border: 3px solid var(--outline); border-radius: 8px; }
.hint-line { text-align: center; margin-top: 10px; min-height: 1.4em; color: #ffe9bd; font-weight: 600; }
.mini-note { font-size: .75em; color: #ffd98a; font-weight: 600; }

/* ---------- crown badge ---------- */
.crown-badge {
  font-family: var(--font-display); font-weight: 800;
  background: linear-gradient(180deg, #4a2f13, #34210c);
  border: 3px solid var(--outline); border-radius: 999px;
  color: var(--gold); padding: 6px 16px 8px;
  box-shadow: 0 4px 0 rgba(0,0,0,.3), inset 0 2px 0 rgba(255,255,255,.08);
  font-size: calc(1.05rem * var(--text-scale));
}

/* ---------- toasts ---------- */
#toast-root { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: linear-gradient(180deg, var(--wood-hi), var(--wood-mid));
  border: 3px solid var(--outline); border-radius: 12px;
  padding: 8px 20px 10px; font-weight: 700; color: var(--cream);
  box-shadow: 0 5px 0 rgba(0,0,0,.3);
  animation: toastIn .25s ease-out;
}
.toast.gold { background: linear-gradient(180deg, #ffd35c, #d88a10); color: #5a3505; }
.toast.bad { background: linear-gradient(180deg, #f2695a, var(--red-dark)); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(.9); } to { opacity: 1; } }
.toast.out { opacity: 0; transition: opacity .4s; }

/* ---------- dialogs ---------- */
#dialog-root:not(:empty) { position: fixed; inset: 0; z-index: 400; display: grid; place-items: center; background: rgba(10,16,25,.55); }
.dialog { width: min(480px, 92vw); text-align: center; }
.dialog h2 { font-family: var(--font-display); margin-bottom: 10px; color: #ffe9bd; }
.dialog p { margin-bottom: 16px; white-space: pre-line; }
.dialog .row { justify-content: center; gap: 14px; }
.dialog textarea { width: 100%; height: 120px; margin-bottom: 12px; border-radius: 10px; border: 3px solid var(--outline); padding: 8px; font: inherit; color: var(--ink); background: var(--cream); resize: none; }

/* ---------- error overlay / tiny screen ---------- */
#error-overlay, #tiny-screen { position: fixed; inset: 0; z-index: 500; display: grid; place-items: center; background: rgba(12,8,4,.8); }
.error-panel { width: min(560px, 92vw); text-align: center; }
.error-panel pre {
  text-align: left; background: rgba(0,0,0,.35); border-radius: 8px; padding: 10px;
  font-size: .72rem; max-height: 130px; overflow: auto; margin: 12px 0; white-space: pre-wrap; user-select: text;
}
#tiny-screen { z-index: 450; }

/* ---------- debug overlay ---------- */
#debug-overlay {
  position: fixed; right: 10px; top: 10px; z-index: 350;
  background: rgba(8,12,18,.88); border: 2px solid #4af; border-radius: 10px;
  color: #bfe3ff; font: 12px/1.5 Consolas, monospace; padding: 10px 12px;
  width: 250px; user-select: text;
}
#debug-overlay h3 { color: #7fd0ff; font-size: 12px; margin-bottom: 4px; }
#debug-overlay .btn { font-size: .68rem; padding: 3px 8px 4px; margin: 2px 2px 2px 0; box-shadow: 0 2px 0 #241505; }
#debug-overlay label { display: block; }

/* high contrast mode */
body.high-contrast .panel.wood { border-width: 5px; box-shadow: 0 0 0 3px #000, var(--panel-shadow); }
body.high-contrast .btn { border-width: 4px; text-shadow: 0 2px 2px rgba(0,0,0,.8); }
body.high-contrast { --cream: #ffffff; }

/* reduced motion */
body.reduced-motion *, body.reduced-motion *::before, body.reduced-motion *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
