:root {
  --ink: #2e2116;
  --ink-soft: #5b4532;
  --paper: #ecdfc3;
  --paper-dark: #d8c49c;
  --edge: #a98a5c;
  --azur: #3b6ea8;
  --gueules: #b3302a;
  --gold: #c99a3a;
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, "Times New Roman", serif;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.25 0 0 0 0 0.12 0 0 0 0.16 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #120c08; color: var(--ink); font-family: var(--serif); user-select: none; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }
.screen { position: fixed; inset: 0; pointer-events: none; }
.screen > * { pointer-events: auto; }

/* ------------------------------------------------------------ paper & wax */
.parchment {
  background: var(--grain), radial-gradient(ellipse at 30% 20%, #f6ecd4 0%, var(--paper) 45%, var(--paper-dark) 100%);
  border: 1px solid var(--edge);
  border-radius: 4px 7px 5px 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), inset 0 0 40px rgba(120, 80, 30, 0.25);
  color: var(--ink);
}
h1, h2, h3 { font-weight: normal; font-variant: small-caps; letter-spacing: 0.06em; margin: 0; }
.seal {
  width: 112px; height: 112px; border-radius: 50%;
  border: none; cursor: pointer;
  font-family: var(--serif); font-size: 17px; font-variant: small-caps; letter-spacing: 0.04em; line-height: 1.05;
  color: #f7dcc8; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 190, 170, 0.25);
  background: radial-gradient(circle at 38% 32%, #d0493d 0%, #9e221b 48%, #6a120d 100%);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.55), inset 0 0 0 7px rgba(110, 20, 14, 0.55), inset 0 0 0 9px rgba(230, 120, 100, 0.2), inset 0 -6px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s, filter 0.12s;
  clip-path: polygon(50% 0%, 61% 3%, 72% 1%, 80% 8%, 91% 11%, 95% 22%, 100% 32%, 98% 44%, 100% 56%, 96% 67%, 97% 79%, 88% 87%, 80% 96%, 68% 97%, 57% 100%, 45% 98%, 33% 100%, 23% 94%, 12% 90%, 6% 79%, 1% 68%, 3% 56%, 0% 44%, 4% 33%, 3% 21%, 11% 12%, 21% 6%, 32% 4%, 41% 0%);
}
.seal:hover { transform: scale(1.06) rotate(-3deg); filter: brightness(1.12); }
.seal:active { transform: scale(0.96); }
.seal:disabled { filter: grayscale(0.8) brightness(0.7); cursor: default; transform: none; }
.btn {
  font-family: var(--serif); font-size: 15px; color: var(--ink); cursor: pointer;
  background: linear-gradient(#f3e7cc, #dcc79f); border: 1px solid var(--edge); border-radius: 3px;
  padding: 6px 12px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.btn.on { background: linear-gradient(#e1c47e, #c99a3a); }
.btn.red { background: linear-gradient(#d9705f, #a8382b); color: #fff2e6; border-color: #7a2219; }

/* ------------------------------------------------------------ title */
#title .hero {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -52%) rotate(-0.6deg);
  width: min(560px, 92vw); padding: 26px 40px 22px; text-align: center;
}
.crown-mark { font-size: 40px; color: var(--gold); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); line-height: 1; }
#title h1 { font-size: 54px; line-height: 0.95; color: #3a2414; text-shadow: 0 2px 0 rgba(255, 255, 255, 0.35); }
#title h1 span { font-size: 40px; color: var(--gueules); }
.sub { font-style: italic; color: var(--ink-soft); margin: 12px 0 16px; font-size: 15px; }
#nameInput {
  width: 78%; font-family: var(--serif); font-size: 21px; text-align: center; color: var(--ink);
  background: transparent; border: none; border-bottom: 2px solid var(--ink-soft); padding: 6px; outline: none;
}
#nameInput::placeholder { color: rgba(70, 50, 30, 0.45); font-style: italic; }
#playBtn { display: block; margin: 16px auto 8px; }
.rules { text-align: left; font-size: 13.5px; color: var(--ink-soft); padding-left: 18px; margin: 10px 0 0; line-height: 1.45; }
.side { position: absolute; top: 50%; transform: translateY(-50%); width: 250px; padding: 16px 18px; font-size: 14px; }
.side.left { left: 26px; transform: translateY(-50%) rotate(1deg); }
.side.right { right: 26px; transform: translateY(-50%) rotate(-1deg); }
.side h2 { font-size: 22px; margin-bottom: 8px; border-bottom: 1px solid var(--edge); padding-bottom: 4px; }
.throne-name { font-size: 22px; color: var(--gueules); margin: 4px 0; }
.muted { color: var(--ink-soft); font-style: italic; font-size: 13px; }
.leaders { list-style: none; padding: 0; margin: 0; }
.leaders li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dotted rgba(90, 60, 30, 0.3); }
.leaders li b { color: var(--ink-soft); width: 22px; display: inline-block; }
#lanInfo { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); color: #d9c49b; font-size: 14px; text-shadow: 0 1px 3px #000; text-align: center; }
#lanInfo b { color: #f3dfb0; font-size: 16px; }

/* ------------------------------------------------------------ council */
#topbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; align-items: center; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.pill {
  background: var(--grain), linear-gradient(#f1e4c6, #d9c39a); border: 1px solid var(--edge); border-radius: 18px;
  padding: 5px 14px; font-size: 18px; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45); white-space: nowrap;
}
#portalBtn { position: absolute; top: 10px; left: 12px; z-index: 6; font: inherit; font-size: 15px; color: inherit; cursor: pointer; }
.pill .ico { color: var(--gold); font-size: 20px; margin-right: 4px; }
#timer.hurry { color: #fff; background: linear-gradient(#cf5444, #93241b); }
.presage { font-size: 15px; max-width: 330px; white-space: normal; line-height: 1.15; }
.presage small { display: block; color: var(--ink-soft); font-size: 12px; font-style: italic; }
#roundSeals { display: flex; gap: 4px; }
.rs { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #f6e6c9; background: #6b5238; border: 1px solid #3e2c1a; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4); }
.rs.win { background: radial-gradient(circle at 35% 30%, #5f8dc4, #2b5487); }
.rs.loss { background: radial-gradient(circle at 35% 30%, #c9534a, #82211b); }
.rs.draw { background: radial-gradient(circle at 35% 30%, #b9a27a, #7d6849); }
.rs.now { background: radial-gradient(circle at 35% 30%, #f2d27c, #b98a2c); color: #3a2410; transform: scale(1.18); }
.rs.throne { font-size: 15px; }

#shop { position: absolute; left: 12px; top: 64px; bottom: 12px; width: 236px; padding: 10px; overflow-y: auto; }
#shop h3 { font-size: 17px; margin: 4px 2px 6px; color: var(--ink-soft); border-bottom: 1px solid var(--edge); }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.card {
  position: relative; background: linear-gradient(#fbf3df, #ecdcb8); border: 1px solid var(--edge); border-radius: 4px;
  padding: 5px 4px 4px; text-align: center; cursor: pointer; transition: transform 0.08s; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
}
.card:hover { transform: translateY(-2px); }
.card.sel { outline: 3px solid var(--gold); background: linear-gradient(#fff6dd, #f0d7a0); }
.card.poor { opacity: 0.45; }
.card svg { width: 46px; height: 40px; display: block; margin: 0 auto; }
.card .nm { font-size: 12.5px; line-height: 1.05; min-height: 26px; display: flex; align-items: center; justify-content: center; }
.card .cost { position: absolute; top: 2px; right: 4px; font-size: 13px; font-weight: bold; color: #7a5410; }
.card .cost.free { color: #2c7a2c; }
.card.unit { background: linear-gradient(#f4f0e6, #dde3e8); }
.card.unit.sel { background: linear-gradient(#fff6dd, #f0d7a0); }
#tooltip { position: fixed; z-index: 30; width: 230px; padding: 8px 10px; font-size: 13px; pointer-events: none; }
#tooltip b { font-size: 15px; }
#tooltip .stats { color: var(--ink-soft); margin-top: 4px; font-size: 12.5px; }

#oppCard { position: absolute; right: 12px; top: 64px; width: 236px; padding: 10px 12px; font-size: 14px; }
#oppCard h3 { font-size: 15px; color: var(--ink-soft); }
#oppCard .oname { font-size: 21px; color: var(--gueules); margin: 2px 0; }
#oppCard.throne { box-shadow: 0 0 0 3px var(--gold), 0 10px 30px rgba(0, 0, 0, 0.55); }
#info { position: absolute; right: 12px; top: 218px; width: 236px; padding: 10px 12px; font-size: 14px; }
#info h3 { font-size: 19px; }
#info .lv { color: var(--gold); letter-spacing: 2px; }
#info .stats { margin: 6px 0; color: var(--ink-soft); line-height: 1.4; }
#info .row { display: flex; gap: 6px; margin-top: 6px; }
#info .row .btn { flex: 1; }

#readyBtn { position: absolute; right: 30px; bottom: 26px; }
.seal.big { width: 132px; height: 132px; font-size: 21px; }
#help { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); color: #d9c49b; font-size: 13px; text-shadow: 0 1px 3px #000; pointer-events: none; white-space: nowrap; }

#edicts { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 10px; }
#edicts h2 { color: #f3dfb0; font-size: 30px; text-shadow: 0 2px 6px #000; }
#edicts .row { display: flex; gap: 16px; }
.edict {
  width: 190px; min-height: 170px; padding: 16px 14px 12px; text-align: center; cursor: pointer; transition: transform 0.12s;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.edict:nth-child(1) { transform: rotate(-2deg); }
.edict:nth-child(3) { transform: rotate(2deg); }
.edict:hover { transform: translateY(-6px) rotate(0deg); }
.edict h3 { font-size: 19px; color: var(--gueules); }
.edict p { margin: 0; font-size: 14px; }
.edict .mini-seal { width: 30px; height: 30px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #d0493d, #6a120d); margin-top: auto; }
#edictReopen { position: absolute; left: 260px; top: 64px; }

/* ------------------------------------------------------------ battle */
#bars { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 16px; align-items: center; pointer-events: none; }
.bar { width: 300px; color: #f6e8cc; text-shadow: 0 1px 3px #000; font-size: 17px; }
.bar.gueules { text-align: right; }
.track { height: 16px; margin-top: 3px; background: rgba(30, 20, 12, 0.75); border: 1px solid #a98a5c; border-radius: 3px; overflow: hidden; }
.track i { display: block; height: 100%; width: 100%; transition: width 0.2s; }
.azur .track i { background: linear-gradient(#6d9bd3, #2f5d93); }
.gueules .track i { background: linear-gradient(#e0665b, #9a2a22); margin-left: auto; }
#battleClock { color: #f3dfb0; font-size: 22px; font-variant: small-caps; text-shadow: 0 2px 4px #000; min-width: 90px; text-align: center; }
#speed { position: absolute; bottom: 16px; right: 16px; display: flex; gap: 6px; }
#banner {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); pointer-events: none;
  font-size: 72px; font-variant: small-caps; color: #f6e2b8; letter-spacing: 0.08em; text-shadow: 0 4px 0 #6a120d, 0 8px 22px #000;
  opacity: 0; transition: opacity 0.4s;
}
#banner.show { opacity: 1; }

/* ------------------------------------------------------------ result & end */
#result, #end { background: rgba(10, 6, 3, 0.35); }
.scroll { position: absolute; left: 50%; top: 54%; transform: translate(-50%, -50%) rotate(0.4deg); width: min(500px, 92vw); padding: 22px 30px; text-align: center; }
.scroll h2 { font-size: 40px; }
.scroll h2.win { color: var(--azur); }
.scroll h2.loss { color: var(--gueules); }
.scroll .line { display: flex; justify-content: space-between; font-size: 17px; padding: 4px 0; border-bottom: 1px dotted rgba(90, 60, 30, 0.35); }
.scroll .line b { color: #7a5410; }
.scroll .big { font-size: 22px; }
.scroll .btn { margin-top: 14px; font-size: 18px; padding: 8px 22px; }
.scroll .hist { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
#stamps { position: absolute; left: 50%; top: 16%; transform: translateX(-50%); display: flex; gap: 22px; pointer-events: none; }
.stamp {
  font-size: 34px; font-variant: small-caps; letter-spacing: 0.06em; padding: 4px 18px; border: 5px double currentColor; border-radius: 8px;
  color: #b3302a; background: rgba(240, 225, 200, 0.12); text-shadow: 0 0 1px currentColor; opacity: 0.92;
  white-space: nowrap;
  animation: stamp 0.35s cubic-bezier(.2, 1.6, .5, 1) both; mix-blend-mode: normal;
}
.stamp.gold { color: #e0b24a; }
.stamp.blue { color: #6f9fd6; }
@keyframes stamp { from { transform: scale(2.6) rotate(-14deg); opacity: 0; } to { transform: scale(1) rotate(-7deg); opacity: 0.92; } }

/* ------------------------------------------------------------ news / toast */
#news { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; z-index: 20; }
.news { padding: 8px 16px; font-size: 16px; animation: drop 0.4s ease-out; }
.news.throne { font-size: 22px; color: var(--gueules); box-shadow: 0 0 0 3px var(--gold), 0 10px 30px rgba(0, 0, 0, 0.55); }
@keyframes drop { from { transform: translateY(-20px); opacity: 0; } to { transform: none; opacity: 1; } }
#toast { position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%); color: #fff0d8; background: rgba(110, 25, 18, 0.88); padding: 6px 14px; border-radius: 4px; font-size: 16px; opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 20; }
#toast.show { opacity: 1; }
#fatal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 6, 3, 0.8); color: #f3dfb0; font-size: 22px; text-align: center; z-index: 50; }
#labels { position: fixed; inset: 0; pointer-events: none; }
.lbl { position: absolute; transform: translate(-50%, -100%); color: #f6e8cc; font-size: 15px; text-shadow: 0 1px 3px #000, 0 0 6px #000; white-space: nowrap; }
.lbl.big { font-size: 19px; font-variant: small-caps; }

@media (max-width: 1100px) {
  .side { display: none; }
  #shop { width: 200px; }
  #oppCard, #info { width: 200px; }
  .bar { width: 190px; }
}
