:root {
  --ink: #1f1f24;
  --paper: #f7f2e7;
  --p0: #2b4fd8;
  --p1: #d8342b;
  --k: #1f1f24; --r: #e63946; --b: #2d6cdf; --g: #21a366; --y: #f2a900;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Patrick Hand", "Comic Neue", "Segoe Print", "Bradley Hand", "Chalkboard SE", "Comic Sans MS", cursive;
  color: var(--ink);
  background: var(--paper);
  background-image: radial-gradient(rgba(0,0,0,.07) 1px, transparent 1px);
  background-size: 18px 18px;
  min-height: 100vh;
  font-size: 18px;
}
.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 22px; }
.top h1 { margin: 0; font-size: 34px; letter-spacing: 1px; transform: rotate(-1.5deg); }
.top h1 span { color: var(--r); }
.status {
  border: 2px solid var(--ink); border-radius: 999px; padding: 2px 12px; font-size: 15px; background: #fff;
}
.status.ok { background: #d8f5e5; }
.status.bad { background: #ffd9d9; }

.screen { display: none; max-width: 1700px; margin: 0 auto; padding: 0 16px 30px; }
.screen.active { display: block; }
#lobby { max-width: 1000px; }

.tag { text-align: center; font-size: 21px; margin: 4px 0 14px; }
.name { display: block; text-align: center; margin-bottom: 18px; }
input, textarea {
  font: inherit; border: 2px solid var(--ink); border-radius: 8px; padding: 6px 10px; background: #fff;
}
.name input { width: 200px; margin-left: 8px; }
textarea { width: 100%; height: 74px; font-family: ui-monospace, monospace; font-size: 11px; resize: vertical; margin: 6px 0; word-break: break-all; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 760px) { .cards { grid-template-columns: 1fr; } }
.card {
  background: #fff; border: 3px solid var(--ink);
  border-radius: 14px 20px 12px 22px; box-shadow: 5px 5px 0 var(--ink); padding: 16px 18px;
}
.card h2 { margin: 0 0 10px; }
.card ol { padding-left: 20px; margin: 12px 0 0; }
.card li { margin-bottom: 10px; }
.hint { opacity: .7; font-size: 16px; }
.msg { text-align: center; color: var(--r); min-height: 24px; }
.how { margin-top: 18px; background: #fff; border: 2px dashed var(--ink); border-radius: 12px; padding: 10px 16px; }
.how summary { cursor: pointer; font-size: 20px; }
.c-k { color: var(--k); } .c-r { color: var(--r); } .c-b { color: var(--b); } .c-g { color: var(--g); } .c-y { color: #c98a00; }

.btn {
  font: inherit; font-size: 19px; cursor: pointer; background: #fff; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 10px 14px 9px 13px; padding: 6px 16px;
  box-shadow: 3px 3px 0 var(--ink); transition: transform .06s, box-shadow .06s;
}
.btn:hover { background: #fff6d6; }
.btn:active { transform: translate(3px,3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { font-size: 15px; padding: 3px 10px; box-shadow: 2px 2px 0 var(--ink); }
.btn.big { font-size: 24px; padding: 8px 22px; background: #ffe066; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* game */
#field {
  display: block; margin: 0 auto; background: #fff; touch-action: none; cursor: crosshair;
  border: 3px solid var(--ink); border-radius: 12px; box-shadow: 5px 5px 0 var(--ink);
  aspect-ratio: 16 / 9;
  width: min(100%, calc((100vh - 215px) * 16 / 9));
}
.dock { width: min(100%, calc((100vh - 215px) * 16 / 9)); margin: 14px auto 0; display: flex; gap: 18px; align-items: stretch; flex-wrap: wrap; }
.units { display: flex; gap: 10px; flex-wrap: wrap; }
.ucard {
  width: 112px; background: #fff; border: 3px solid var(--ink); border-radius: 12px 14px 10px 15px; cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink); padding: 4px 6px; text-align: center; font: inherit; color: var(--ink); position: relative;
  transition: transform .08s;
}
.ucard canvas { width: 70px; height: 56px; display: block; margin: 0 auto; }
.ucard b { display: block; font-size: 18px; line-height: 1; }
.ucard small { display: block; font-size: 13px; opacity: .75; }
.ucard .cost { position: absolute; top: 3px; right: 6px; font-size: 14px; }
.ucard .key { position: absolute; top: 3px; left: 7px; font-size: 13px; opacity: .55; }
.ucard.sel { transform: translateY(-5px); background: #fff4c2; }
.ucard.poor { opacity: .5; }
.inkbox { flex: 1; min-width: 220px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.inklabel { font-size: 20px; }
.meter { height: 22px; border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; background: #fff; }
#inkBar { height: 100%; width: 0; transition: width .12s; }
.count { font-size: 56px; margin: 4px 0 0; }

/* overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(247,242,231,.82); display: grid; place-items: center; z-index: 10;
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }
.panel {
  background: #fff; border: 3px solid var(--ink); border-radius: 16px 22px 14px 20px; box-shadow: 6px 6px 0 var(--ink);
  padding: 20px 28px; text-align: center; max-width: 94vw; animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.85) rotate(-2deg); opacity: 0; } }
.panel h2 { margin: 0 0 10px; font-size: 34px; }

.linkbox { width: 100%; font-family: ui-monospace, monospace; font-size: 14px; margin: 6px 0; background: #fffbe8; }
.roomcode { font-family: ui-monospace, monospace; font-size: 24px; letter-spacing: 3px; background: #fff4c2; padding: 0 8px; border-radius: 6px; }
.roomin { width: 150px; font-family: ui-monospace, monospace; font-size: 20px; letter-spacing: 2px; text-transform: lowercase; }
