:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #6b7385;
  --border: #dfe3ec;
  --primary: #2f6df6;
  --primary-text: #ffffff;
  --accent: #f0f4ff;
  --p0: #e5484d;
  --p1: #2f6df6;
  --ok: #30a46c;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --surface: #1b2029;
    --text: #e8ebf2;
    --muted: #949bab;
    --border: #2c3340;
    --primary: #5b8cff;
    --accent: #222a3a;
    --p0: #ff6b70;
    --p1: #6b9bff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.6;
}
[hidden] { display: none !important; }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .6rem; }
a { color: var(--primary); text-decoration: none; }

input, button {
  font: inherit;
  color: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: .55rem .9rem;
}
input { min-width: 0; flex: 1; }
input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: var(--primary); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.linklike { border: none; background: none; padding: 0; color: var(--primary); }
.chip { padding: .3rem .75rem; font-size: .9rem; border-radius: 999px; }
.row { display: flex; gap: .5rem; }
.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.logo { font-weight: 700; color: var(--text); margin-right: auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .logo { font-size: .9rem; } .topbar { gap: .5rem; } }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.conn.on { background: var(--ok); }
main { max-width: 980px; margin: 0 auto; padding: 1rem 16px 3rem; }
.back { display: inline-block; font-size: .9rem; margin-bottom: .4rem; }

.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 1rem 1.1rem; box-shadow: var(--shadow); color: var(--text);
}
a.card:hover { border-color: var(--primary); }
.game-card .icon { font-size: 2rem; }
.game-card h3 { margin: .2rem 0; font-size: 1.1rem; }

/* 昔の個人サイト風アクセスカウンター */
.counter { margin: 2.5rem auto 0; text-align: center; font-size: .9rem; color: var(--muted); }
.counter .digits { display: inline-flex; gap: 2px; vertical-align: middle; margin: 0 .25rem; }
.counter .digits span {
  font-family: "Courier New", ui-monospace, monospace; font-weight: 700; font-size: 1.25rem; line-height: 1;
  color: #7dff6a; background: #111; border: 1px solid #444; border-radius: 3px; padding: .2rem .28rem;
  text-shadow: 0 0 6px rgba(125, 255, 106, .7);
}
.counter-sub { font-size: .75rem; letter-spacing: .05em; margin-top: .4rem; }
.counter-sub b { color: var(--text); }

.room-list { display: grid; gap: .6rem; }
.room-item { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.room-item .info { flex: 1; min-width: 160px; }
.room-item .name { font-weight: 600; }
.badge { font-size: .75rem; padding: .1rem .55rem; border-radius: 999px; background: var(--accent); color: var(--muted); }
.badge.waiting { color: var(--ok); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); border: 1px dashed var(--border); border-radius: 14px; }

.room-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.room-head h1 { margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.room-head .back { margin: 0; }
.room-layout { display: grid; grid-template-columns: 1fr 280px; gap: 1rem; margin-top: 1rem; }
@media (max-width: 760px) { .room-layout { grid-template-columns: 1fr; } }
.room-main, .room-side { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1rem; box-shadow: var(--shadow); }
.room-side { display: flex; flex-direction: column; gap: .5rem; min-height: 260px; }

.seats { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.seat { border: 2px solid var(--border); border-radius: 12px; padding: .5rem .75rem; display: flex; align-items: center; gap: .6rem; min-width: 0; }
.seat.turn { border-color: var(--primary); background: var(--accent); }
.seat .mark { font-size: 1.4rem; font-weight: 700; width: 1.6rem; text-align: center; }
.seat .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .me { font-size: .75rem; color: var(--primary); font-weight: 700; margin-left: .3rem; }
.seat.off .who::after { content: "（切断中…）"; color: var(--muted); font-size: .8rem; }
.p0 { color: var(--p0); }
.p1 { color: var(--p1); }

.status { text-align: center; font-weight: 600; margin: 1rem 0 .5rem; min-height: 1.6em; }
.status.win { color: var(--ok); }
.board-wrap { display: flex; justify-content: center; }
.actions { display: flex; justify-content: center; gap: .5rem; margin-top: 1rem; min-height: 2.6rem; }

.chat-log { flex: 1; overflow-y: auto; max-height: 360px; font-size: .9rem; display: flex; flex-direction: column; gap: .2rem; }
.chat-log .sys { color: var(--muted); font-size: .8rem; }
.chat-log .from { font-weight: 600; margin-right: .3rem; }
.chat-log div { overflow-wrap: anywhere; }

dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); width: min(360px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog input { width: 100%; margin-bottom: 1rem; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1.1rem; border-radius: 10px;
  max-width: calc(100% - 32px); z-index: 10;
}
