:root {
  --ink: #0a0a0a;
  --paper: #f2efe8;
  --grey: #8a8780;
  --dim: #55524c;
  --mono: ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
  --mincho: "Shippori Mincho B1", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --brush: "Reggae One", "Shippori Mincho B1", "Yu Mincho", serif;
  /* 手描きっぽく歪ませた角 */
  --rough-radius: 3px 14px 4px 12px / 12px 4px 14px 3px;
  --stroke-shape: polygon(0 55%, 3% 12%, 55% 0, 100% 35%, 97% 78%, 45% 100%, 2% 88%);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mincho);
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.defs { position: absolute; width: 0; height: 0; }

/* ---------- HUD ---------- */
.hud {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 8px 14px 12px;
  background: var(--ink);
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.hud::after,
.server::before {
  content: "";
  position: absolute;
  left: -1%;
  right: -1%;
  height: 9px;
  background: var(--paper);
  clip-path: var(--stroke-shape);
  filter: url(#rough);
}
.hud::after { bottom: -3px; }
.hud-item { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.hud-hp { flex: 1; min-width: 0; }
.label { color: var(--grey); font-size: 11px; letter-spacing: .2em; }
.hpbar {
  flex: 1;
  height: 12px;
  min-width: 40px;
  border: 2px solid var(--paper);
  border-radius: var(--rough-radius);
  overflow: hidden;
  background: var(--ink);
}
#hpfill {
  height: 100%;
  width: 100%;
  background: var(--paper);
  transition: width .25s;
}
#hpfill.low {
  background: repeating-linear-gradient(135deg, var(--paper) 0 6px, var(--ink) 6px 10px);
  animation: blink .5s steps(2) infinite;
}
@keyframes blink { 50% { opacity: .45; } }

/* ---------- Field ---------- */
#field {
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: crosshair;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .14 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E"),
    var(--ink);
}
#field::before {
  content: "斬";
  position: absolute;
  right: -3%;
  bottom: -9%;
  font-family: var(--brush);
  font-size: min(78vh, 95vw);
  line-height: 1;
  color: var(--paper);
  opacity: .055;
  pointer-events: none;
}
#field.hit { animation: hit .38s; }
@keyframes hit {
  0% { filter: invert(1); }
  30% { filter: invert(1); transform: translateX(-9px); }
  31% { filter: none; }
  70% { transform: translateX(7px); }
  100% { transform: none; }
}

.chip {
  position: absolute;
  top: 0;
  left: 0;
  max-width: min(94%, 540px);
  padding: 7px 11px;
  border: 2px solid var(--ink);
  border-radius: var(--rough-radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 3px 4px 0 rgba(242, 239, 232, .28);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
  will-change: transform;
  transition: opacity .25s;
}
.chip:hover { outline: 2px solid var(--paper); outline-offset: 2px; }
.chip .u { word-break: break-all; }
.chip .meta { margin-top: 2px; color: var(--dim); font-size: 11px; word-break: break-all; }
.chip.wrong { opacity: 0; pointer-events: none; }
.chip.passed { opacity: 0; pointer-events: none; }
.chip.breach {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--paper);
  pointer-events: none;
}
.chip.breach .meta { color: var(--grey); }
.chip.half { pointer-events: none; transition: none; box-shadow: none; }

.m {
  display: inline-block;
  padding: 0 5px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
}
.chip.breach .m { background: var(--paper); color: var(--ink); }

/* 斬撃。difference 合成で、黒地では白、白い札の上では黒い線になる */
.slash {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
  height: 9px;
  background: #fff;
  clip-path: polygon(0 50%, 22% 0, 100% 50%, 22% 100%);
  mix-blend-mode: difference;
  pointer-events: none;
}

.float {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  font-family: var(--brush);
  font-size: 22px;
  color: var(--paper);
  pointer-events: none;
  text-shadow: 0 0 6px #000, 0 0 2px #000;
  animation: floatup .9s ease-out forwards;
  white-space: nowrap;
}
.float.bad { text-decoration: line-through; }
@keyframes floatup {
  to { margin-top: -44px; opacity: 0; }
}

#banner {
  position: absolute;
  top: 36%;
  left: 0;
  right: 0;
  z-index: 5;
  text-align: center;
  font-family: var(--brush);
  font-size: clamp(22px, 5.4vw, 44px);
  color: var(--paper);
  text-shadow: 0 0 12px #000, 0 0 3px #000;
  opacity: 0;
  pointer-events: none;
  filter: url(#rough-s);
}
#banner.show { animation: banner 2.2s ease-out; }
@keyframes banner {
  0% { opacity: 0; transform: scale(1.25); }
  12%, 70% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

/* ---------- Server ---------- */
.server {
  position: relative;
  padding: 12px 14px calc(8px + env(safe-area-inset-bottom));
  background: var(--ink);
  text-align: center;
}
.server::before { top: -5px; height: 11px; }
#log {
  display: inline-block;
  max-width: 100%;
  min-height: 1.6em;
  padding: 0 8px;
  font-size: 14px;
  color: var(--grey);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
#log.ok { color: var(--paper); }
#log.bad { background: var(--paper); color: var(--ink); font-weight: 800; }
.server-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .22em;
  color: var(--paper);
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .9);
  overflow-y: auto;
}
.overlay.hidden { display: none; }

.panel {
  width: 100%;
  max-width: 560px;
  max-height: 100%;
  overflow-y: auto;
  padding: 24px 24px 26px;
  border: 5px solid var(--ink);
  border-radius: var(--rough-radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 0 0 2px var(--paper);
  -webkit-user-select: text;
  user-select: text;
}

.kicker {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .3em;
}
.kicker.bad {
  display: inline-block;
  padding: 3px 10px;
  background: var(--ink);
  color: var(--paper);
  letter-spacing: .12em;
}

h1 {
  margin: 0;
  font-family: var(--brush);
  font-weight: 400;
  font-size: clamp(30px, 8.4vw, 52px);
  line-height: 1.2;
  filter: url(#rough-s);
}
h1 span {
  padding: 0 .12em;
  background: var(--ink);
  color: var(--paper);
}
.ink {
  height: 16px;
  margin: 8px -6px 14px;
  background: var(--ink);
  clip-path: var(--stroke-shape);
  filter: url(#rough);
}
h2 {
  margin: 0 0 12px;
  font-family: var(--brush);
  font-weight: 400;
  font-size: 28px;
}
h3 {
  margin: 18px 0 4px;
  padding-left: 8px;
  border-left: 6px solid var(--ink);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .1em;
}
p { margin: 0 0 8px; line-height: 1.75; font-size: 14px; }
.lead { color: var(--dim); }
code { font-family: var(--mono); text-decoration: underline; }

.rules {
  margin: 14px 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.95;
}
.rules b {
  font-weight: 800;
  background: linear-gradient(transparent 62%, rgba(10, 10, 10, .2) 62%);
}

.best { color: var(--dim); font-size: 13px; }

.req {
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: var(--rough-radius);
  background: #fbfaf6;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-all;
  max-height: 9.5em;
  overflow-y: auto;
}
.req .meta { margin-top: 4px; color: var(--dim); font-size: 11px; }
mark {
  padding: 0 2px;
  background: var(--ink);
  color: var(--paper);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 2px solid var(--ink);
  border-radius: var(--rough-radius);
}
.stats .label { color: var(--dim); }
.stats b { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

.review { margin: 0; padding: 0; list-style: none; }
.review li {
  padding: 8px 0;
  border-top: 1px solid var(--ink);
  font-size: 13px;
  line-height: 1.65;
}
.review b { font-weight: 800; }

.actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  display: inline-block;
  flex: 1;
  width: 100%;
  margin-top: 14px;
  padding: 12px 16px;
  border: 3px solid var(--ink);
  border-radius: var(--rough-radius);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--brush);
  font-size: 19px;
  letter-spacing: .2em;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.actions .btn { margin-top: 0; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn:hover { background: var(--paper); color: var(--ink); }
.btn.ghost:hover { background: var(--ink); color: var(--paper); }

@media (max-width: 480px) {
  .hud { gap: 10px; padding: 6px 10px 10px; font-size: 14px; }
  .chip { font-size: 12px; }
  .panel { padding: 18px 16px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  #field.hit { animation: none; }
  #hpfill.low { animation: none; }
}
