:root { --ink: #111; --muted: #888; --line: #ddd; --p1: #d7263d; --p2: #1b5fd9; }
* { box-sizing: border-box; }
html, body { margin: 0; background: #fff; color: var(--ink); }
body {
  font-family: "Comic Sans MS", "Comic Sans", "Chalkboard SE", "Comic Neue", cursive;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 96px;
}
header { text-align: center; margin-bottom: 40px; }
h1 { font-size: 28px; margin: 0 0 4px; }
header p { margin: 0; font-size: 15px; color: var(--muted); }

.arena {
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 28px;
  align-items: center;
}
.player { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.score { display: inline-block; }
.player .label { display: flex; justify-content: space-between; font-size: 18px; }
.p1 .label { color: var(--p1); }
.p2 .label { color: var(--p2); }
input[type=text] {
  width: 100%;
  font: inherit;
  font-size: 24px;
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
.p1 input:focus { border-color: var(--p1); }
.p2 input:focus { border-color: var(--p2); }
input.masked { -webkit-text-security: disc; }
input:disabled { background: #f6f6f6; color: var(--ink); -webkit-text-fill-color: var(--ink); }
.p1 { --pc: var(--p1); }
.p2 { --pc: var(--p2); }
.player { transition: opacity 0.15s; }
.player input { transition: transform 0.15s, background 0.15s; }
.player.winner input:disabled { background: var(--pc); border-color: var(--pc); color: #fff; -webkit-text-fill-color: #fff; transform: scale(1.06); }
.player.winner .hint { font-size: 24px; font-weight: bold; color: var(--pc); }
.player.loser { opacity: 0.25; }
.player.loser input { text-decoration: line-through; }
.timer.verdict { color: var(--pc); font-size: 110px; line-height: 0.6; }
.timer.verdict.same { color: var(--ink); transform: none; }
.player.same input:disabled { background: #ffe45c; border-color: var(--ink); transform: scale(1.04); }
.player.same .hint { font-size: 24px; font-weight: bold; color: var(--ink); }
body.flash0 { animation: flash0 0.9s; }
@keyframes flash0 { 0% { background: rgba(255, 228, 92, 0.55); } }
body.flash1 { animation: flash1 0.9s; }
body.flash2 { animation: flash2 0.9s; }
@keyframes flash1 { 0% { background: rgba(215, 38, 61, 0.28); } }
@keyframes flash2 { 0% { background: rgba(27, 95, 217, 0.28); } }
input.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.hint { font-size: 14px; color: var(--muted); min-height: 34px; }
.hint.error { color: var(--p1); }

.timer { font-size: 64px; width: 120px; text-align: center; font-variant-numeric: tabular-nums; }
.timer.urgent { color: var(--p1); }
.timer.small { font-size: 32px; color: var(--muted); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.timer.clickable { cursor: pointer; }
.score.bump { animation: bump 0.5s; }
@keyframes bump { 40% { transform: scale(1.8); } }
.notice { font-size: 14px; color: var(--p1); min-height: 20px; margin-top: 12px; text-align: center; }

.controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; gap: 16px; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 10px 16px; background: #fff; border-top: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
}
button {
  font: inherit; font-size: 16px;
  background: #fff; color: var(--ink); border: 2px solid var(--ink); border-radius: 8px;
  padding: 8px 16px; cursor: pointer;
}
button:hover { background: #f2f2f2; }
button.ghost { border-color: var(--line); color: var(--muted); }
button[hidden] { display: none; }

dialog { border: 2px solid var(--ink); border-radius: 12px; padding: 24px; text-align: center; font: inherit; color: var(--ink); max-width: calc(100vw - 32px); }
dialog::backdrop { background: rgba(255, 255, 255, 0.85); }
dialog h2 { margin: 0 0 4px; font-size: 24px; }
dialog p { margin: 0 0 16px; font-size: 15px; color: var(--muted); }
.modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.modes button { display: flex; flex-direction: column; align-items: center; padding: 12px 20px; font-size: 18px; }
.modes button small { font-size: 13px; color: var(--muted); }
.modes button.current { background: #fff3a8; }

.used { width: 100%; max-width: 900px; margin-top: 24px; }
.used h2 { font-size: 18px; font-weight: normal; margin: 0 0 12px; color: var(--muted); }
.used ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.used li { font-size: 17px; text-decoration: line-through; color: #666; }
.used .won1 { color: var(--p1); text-decoration: none; }
.used .won2 { color: var(--p2); text-decoration: none; }

@media (max-width: 720px) {
  .arena { grid-template-columns: 1fr; gap: 16px; }
  /* stacked layout: the clock sits between the players, and the verdict sign turns to point up/down */
  .timer { margin: 0 auto; }
  .timer.verdict { transform: rotate(90deg); }
}

/* lobby */
.lobby { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.lobby label { font-size: 18px; }
.lobby input { text-align: center; }
.lobby p { margin: 12px 0 4px; font-size: 15px; color: var(--muted); }

/* online play */
.waiting { text-align: center; margin-top: 8vh; }
.waiting p { font-size: 22px; margin: 0 0 16px; }
.linkbox { position: relative; width: min(460px, 100%); margin: 0 auto; }
.linkbox input { width: 100%; font: inherit; font-size: 16px; padding: 12px 48px 12px 14px; border: 2px solid var(--ink); border-radius: 8px; color: var(--ink); outline: none; text-overflow: ellipsis; }
.linkbox button { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); display: flex; padding: 7px; border: 0; border-radius: 6px; background: none; }
.linkbox button:hover { background: #f0f0f0; }
.linkbox svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.linkbox .icon-done, .linkbox .copied .icon-copy { display: none; }
.linkbox .copied .icon-done { display: block; stroke: #1a9a4b; }
.arena[hidden], .used[hidden], .controls[hidden], .waiting[hidden] { display: none; }
.edit { border: 0; padding: 0 6px 0 0; font-size: 18px; color: inherit; background: none; }
.edit:hover { background: none; opacity: 0.6; }
.share { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.share input { font: inherit; font-size: 15px; padding: 8px 10px; border: 2px solid var(--line); border-radius: 8px; width: min(420px, 80vw); color: var(--ink); }
.notice.info { color: var(--muted); font-size: 16px; }
.you { font-size: 13px; color: var(--muted); margin-left: 6px; }
.controls a { color: var(--muted); transition: color 0.1s; }
.controls a.danger:hover, .controls a.danger:focus-visible { color: var(--p1); }
.share[hidden] { display: none; }
