/* しばりしりとり — 駄菓子屋ポップ
   ソーダ水色の地に、フルーツ色のあめ玉とシール。影はぼかさず、インク色でずらす。 */

:root {
  --soda: #c9f0ff;        /* 背景 */
  --soda-dot: #b0e6fb;
  --paper: #ffffff;       /* カード */
  --paper-2: #f3f0ff;     /* 入力欄・薄い面 */
  --ink: #3a2b5e;         /* ぶどうインク：文字・縁取り・影 */
  --ink-2: #7a6c9c;
  --line: #3a2b5e;
  --strawberry: #ff5c8a;
  --lemon: #ffd43b;
  --melon: #36d399;
  --ramune: #8e7bff;
  --orange: #ff9f43;
  --on-color: #ffffff;
  --seat-0: var(--strawberry);
  --seat-1: var(--melon);
  --seat-2: var(--ramune);
  --seat-3: var(--orange);
  --pop: 3px 3px 0 var(--ink);
  --pop-lg: 5px 5px 0 var(--ink);
  /* 管理画面などで使う旧名 */
  --card: var(--paper);
  --shu: var(--strawberry);
  --ai: var(--ramune);
  --ok: #17a673;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --soda: #241b3d; --soda-dot: #2e2450; --paper: #33285a; --paper-2: #2a2149;
    --ink: #f5efff; --ink-2: #b8acd9; --line: #f5efff; --ok: #4fe0a6;
    --pop: 3px 3px 0 #120c24; --pop-lg: 5px 5px 0 #120c24;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --soda: #241b3d; --soda-dot: #2e2450; --paper: #33285a; --paper-2: #2a2149;
  --ink: #f5efff; --ink-2: #b8acd9; --line: #f5efff; --ok: #4fe0a6;
  --pop: 3px 3px 0 #120c24; --pop-lg: 5px 5px 0 #120c24;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); line-height: 1.7;
  font-family: 'M PLUS Rounded 1c', system-ui, sans-serif; font-weight: 500;
  background-color: var(--soda);
  background-image: radial-gradient(var(--soda-dot) 3px, transparent 3.5px);
  background-size: 28px 28px;
  min-height: 100vh;
}
a { color: var(--ramune); font-weight: 700; }
:focus-visible { outline: 3px solid var(--ramune); outline-offset: 2px; }
.logo, .card h2, dialog h3, .title, .code, .fuda span, .timer span, .ranking .n, .ranking .r, .result li::before, .otp { font-synthesis: none; }

/* ---------- ヘッダー ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; max-width: 980px; margin: 0 auto; }
.logo { font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; white-space: nowrap; font-size: 20px; color: var(--ink); text-decoration: none; letter-spacing: .02em; }
.logo span { color: var(--strawberry); }
#me-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; flex-wrap: wrap; justify-content: flex-end; }
#me-chip img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 2px solid var(--ink); background: var(--paper); }
main { max-width: 980px; margin: 0 auto; padding: 0 16px 56px; }

/* ---------- 部品 ---------- */
.card { background: var(--paper); border: 3px solid var(--line); border-radius: 22px; padding: 20px; box-shadow: var(--pop-lg); }
.card h2 { font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 17px; margin: 0 0 14px; color: var(--ink); }
.narrow { max-width: 440px; margin: 20px auto; }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.wide { grid-column: 1 / -1; }
.lead { color: var(--ink); font-size: 15px; margin: 8px 0 0; }
.sub { font-size: 13px; color: var(--ink-2); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 10px; margin-top: 10px; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 12px; }
input, select, textarea {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--paper-2);
  border: 2.5px solid var(--line); border-radius: 14px; padding: 10px 14px; min-width: 0;
}
input::placeholder { color: var(--ink-2); font-weight: 500; opacity: .8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ramune); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ramune) 30%, transparent); }
input:disabled, select:disabled { opacity: .55; }
.row input { flex: 1; }

/* ボタン：ぷっくりしたシール。押すと影の分だけ沈む */
.btn {
  font: inherit; font-weight: 800; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 2.5px solid var(--line); background: var(--paper); color: var(--ink);
  padding: 9px 18px; border-radius: 999px; cursor: pointer; text-decoration: none;
  box-shadow: var(--pop); transition: transform .08s, box-shadow .08s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: var(--pop); }
.btn.primary { background: var(--strawberry); color: var(--on-color); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; }
.btn.ghost:hover, .btn.ghost:active { transform: none; box-shadow: none; }
.btn.big { width: 100%; padding: 14px; font-size: 18px; margin-bottom: 14px; }
.btn.small { padding: 5px 12px; font-size: 13px; box-shadow: 2px 2px 0 var(--ink); }
.btn.ghost, .btn.ghost.small { box-shadow: none; }
.btn.danger { color: var(--strawberry); border-color: var(--strawberry); background: var(--paper); box-shadow: 2px 2px 0 var(--strawberry); }
a.btn { font-weight: 800; }

.tabs { display: flex; gap: 6px; margin: 18px 0 14px; background: var(--paper-2); padding: 5px; border-radius: 999px; border: 2.5px solid var(--line); }
.tabs button { flex: 1; font: inherit; font-weight: 800; background: none; border: 0; padding: 8px 12px; color: var(--ink-2); cursor: pointer; border-radius: 999px; }
.tabs button.on { background: var(--lemon); color: #3a2b5e; box-shadow: inset 0 0 0 2.5px #3a2b5e; }
.msg { min-height: 1.4em; font-size: 14px; font-weight: 700; color: var(--strawberry); margin: 8px 0 0; }
.msg.ok { color: var(--ok); }
summary { cursor: pointer; font-size: 14px; font-weight: 800; color: var(--ink); margin-top: 10px; }
.rules ul { padding-left: 1.2em; font-size: 14px; margin: 8px 0 0; }
.rules li { margin: 4px 0; }
.rules li::marker { color: var(--strawberry); }

/* ---------- タイトル（あめ玉タイル） ---------- */
.title { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-weight: 400; }
.title span {
  display: grid; place-items: center; width: 52px; height: 52px; font-size: 28px; line-height: 1;
  background: var(--c, var(--strawberry)); color: #3a2b5e; border: 3px solid #3a2b5e; border-radius: 16px;
  box-shadow: 3px 3px 0 #3a2b5e;
}
.title span:nth-child(odd) { transform: rotate(-4deg); }
.title span:nth-child(even) { transform: rotate(3deg); }
.title .gap { width: 100%; height: 0; background: none; border: 0; box-shadow: none; }
.title span:nth-child(1) { --c: var(--lemon); }
.title span:nth-child(2) { --c: var(--melon); }
.title span:nth-child(3) { --c: var(--strawberry); color: #fff; }
.title span:nth-child(5) { --c: #fff; }
.title span:nth-child(6) { --c: var(--ramune); color: #fff; }
.title span:nth-child(7) { --c: var(--orange); }
.title span:nth-child(8) { --c: var(--lemon); }

/* ---------- ホーム ---------- */
.profile { display: flex; gap: 14px; align-items: center; }
.profile form { flex: 1; min-width: 0; flex-wrap: nowrap; }
.avatar-edit { position: relative; cursor: pointer; margin: 0; }
.avatar-edit img { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 3px solid var(--ink); display: block; background: var(--paper-2); box-shadow: var(--pop); }
.avatar-edit span { position: absolute; bottom: -4px; right: -6px; font-size: 11px; font-weight: 800; background: var(--lemon); color: #3a2b5e; border: 2px solid #3a2b5e; border-radius: 999px; padding: 0 7px; }
.stat { font-size: 15px; font-weight: 800; background: var(--paper-2); border-radius: 12px; padding: 8px 12px; display: inline-block; margin: 12px 0 0; }
.ranking { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.ranking li { display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--paper-2); font-weight: 700; }
.ranking .n { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 14px; background: var(--paper); border: 2px solid var(--line); flex: none; }
.ranking li:nth-child(1) .n { background: var(--lemon); color: #3a2b5e; }
.ranking li:nth-child(2) .n { background: #dfe6f5; color: #3a2b5e; }
.ranking li:nth-child(3) .n { background: var(--orange); color: #3a2b5e; }
.ranking img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 2px solid var(--line); }
.ranking .r { margin-left: auto; font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }

/* ---------- 部屋 ---------- */
.room { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
.room > *, .grid > * { min-width: 0; }
.room-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; font-weight: 800; }
.code { font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 22px; letter-spacing: .12em; background: var(--lemon); color: #3a2b5e; border: 2.5px solid #3a2b5e; border-radius: 12px; padding: 0 10px; box-shadow: 2px 2px 0 #3a2b5e; }
.badge { font-size: 12px; font-weight: 800; border: 2px solid var(--line); border-radius: 999px; padding: 2px 10px; background: var(--paper); }

/* プレイヤー：席ごとのフルーツ色 */
.players { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.players li {
  --seat: var(--seat-0);
  display: flex; align-items: center; gap: 10px; position: relative;
  background: var(--paper); border: 3px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 6px;
  box-shadow: var(--pop);
}
.players li:nth-child(2) { --seat: var(--seat-1); }
.players li:nth-child(3) { --seat: var(--seat-2); }
.players li:nth-child(4) { --seat: var(--seat-3); }
.players img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: none; border: 3px solid var(--seat); background: var(--paper-2); }
.players .nm { font-weight: 800; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .rt { font-size: 12px; color: var(--ink-2); font-weight: 700; }
.players .host { font-size: 11px; color: var(--ramune); font-weight: 800; }
.players li.turn { background: var(--seat); border-color: #3a2b5e; color: #3a2b5e; }
.players li.turn .rt, .players li.turn .host { color: #3a2b5e; }
.players li.turn img { border-color: #fff; }
.players li.turn::before {
  content: 'いまの番'; position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; background: var(--ink); color: var(--paper); padding: 1px 10px; border-radius: 999px; white-space: nowrap;
}
.players li.out { opacity: .45; box-shadow: none; filter: grayscale(.8); }
.players li.out .nm { text-decoration: line-through; text-decoration-thickness: 2px; }
.players li.off::after { content: '切断中'; position: absolute; bottom: -10px; right: 12px; font-size: 10px; font-weight: 800; color: #fff; background: var(--strawberry); border-radius: 999px; padding: 0 6px; }
.notice { text-align: center; font-weight: 800; margin: 0 auto; background: var(--lemon); color: #3a2b5e; border: 2.5px solid #3a2b5e; border-radius: 999px; padding: 6px 18px; width: fit-content; max-width: 100%; box-shadow: 2px 2px 0 #3a2b5e; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 14px; }

/* ---------- 対戦：主役のあめ玉札 ---------- */
#board { background: var(--paper); border: 3px solid var(--line); border-radius: 28px; padding: 18px 16px 22px; box-shadow: var(--pop-lg); }
.theme-line { text-align: center; font-size: 14px; font-weight: 800; }
.theme-line.exact { width: fit-content; margin: 0 auto; background: var(--lemon); color: #3a2b5e; border: 2.5px solid #3a2b5e; border-radius: 999px; padding: 2px 14px; }
.theme-line::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--melon); margin-right: 6px; vertical-align: 1px; }
.stage { display: grid; justify-items: center; gap: 14px; padding: 10px 0 4px; }
.last { font-size: 15px; color: var(--ink-2); min-height: 1.6em; font-weight: 700; text-align: center; }
.last b { color: var(--ink); font-size: 20px; }
.fuda {
  width: 168px; height: 168px; display: grid; place-items: center; align-content: center; position: relative;
  background: radial-gradient(circle at 18% 16%, #fffb 0 6%, transparent 6.5%), radial-gradient(circle at 27% 13%, #fff8 0 3%, transparent 3.5%), var(--strawberry);
  border: 4px solid #3a2b5e; border-radius: 40px; box-shadow: 7px 7px 0 #3a2b5e; transform: rotate(-3deg);
}
.fuda span { font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 96px; line-height: 1; color: #fff; -webkit-text-stroke: 3px #3a2b5e; paint-order: stroke fill; }
.fuda small { font-size: 14px; font-weight: 800; color: #3a2b5e; background: #fff; border: 2.5px solid #3a2b5e; border-radius: 999px; padding: 0 12px; position: absolute; bottom: -16px; }
.fuda.pop { animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { 0% { transform: rotate(-3deg) scale(.6); } 100% { transform: rotate(-3deg) scale(1); } }
.judging .fuda { background: radial-gradient(circle at 18% 16%, #fffb 0 6%, transparent 6.5%), radial-gradient(circle at 27% 13%, #fff8 0 3%, transparent 3.5%), var(--ramune); }
.judging .last::after { content: '　AIが判定中…'; color: var(--ramune); font-weight: 800; }

/* タイマー：あめのストライプ */
.timer { width: min(440px, 100%); height: 18px; background: var(--paper-2); border: 2.5px solid var(--line); border-radius: 999px; position: relative; margin-top: 14px; }
.timer div {
  height: 100%; border-radius: 999px; transition: width .2s linear;
  background: repeating-linear-gradient(-45deg, var(--melon) 0 10px, #6ee7b7 10px 20px);
}
.timer div.hurry { background: repeating-linear-gradient(-45deg, var(--strawberry) 0 10px, #ff8fb0 10px 20px); }
.timer span { position: absolute; right: -2px; top: -26px; font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.answer { display: flex; gap: 10px; max-width: 500px; margin: 22px auto 0; }
.answer input { flex: 1; font-size: 22px; text-align: center; border-radius: 999px; padding: 12px 18px; border-width: 3px; }
.answer .btn { font-size: 18px; padding: 0 24px; }
#play-msg { text-align: center; }

/* 観戦：五十音の使用済みチェック */
.gojuon { display: grid; grid-template-rows: repeat(5, auto); grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; direction: rtl; }
.gojuon i { direction: ltr; font-style: normal; text-align: center; font-size: clamp(11px, 2.6vw, 14px); font-weight: 800; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; color: var(--ink-2); background: var(--paper-2); }
.gojuon i.used { background: var(--strawberry); color: #fff; }
.gojuon i.req { box-shadow: 0 0 0 3px var(--ramune); color: var(--ink); background: var(--lemon); }
.gojuon i.blank { background: none; }
.history { margin: 0; padding-left: 1.8em; max-height: 360px; overflow: auto; font-size: 15px; font-weight: 700; }
.history li { padding: 2px 0; }
.history li::marker { color: var(--ink-2); font-size: 12px; }
.history li.ng { color: var(--strawberry); }
.history small { color: var(--ink-2); font-weight: 500; }

/* 結果 */
.result { padding: 0; list-style: none; margin: 0 0 16px; display: grid; gap: 8px; counter-reset: rank; }
.result li { counter-increment: rank; display: flex; gap: 10px; align-items: center; background: var(--paper-2); border-radius: 999px; padding: 6px 14px 6px 6px; font-weight: 700; }
.result li::before { content: counter(rank) '位'; font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 13px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 2.5px solid var(--line); background: var(--paper); flex: none; }
.result li:first-child { background: var(--lemon); color: #3a2b5e; border: 3px solid #3a2b5e; box-shadow: var(--pop); }
.result li:first-child::before { content: '👑'; font-size: 22px; background: #fff; border-color: #3a2b5e; }
.result img { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line); }
.up { color: var(--ok); font-weight: 800; }
.down { color: var(--strawberry); font-weight: 800; }
.result li:first-child .up { color: #0f7a52; }

/* ---------- 認証・セキュリティ ---------- */
.turnstile { margin: 2px 0 10px; }
.turnstile:not(:empty) { min-height: 65px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 13px; font-weight: 700; margin: 18px 0 12px; }
.or::before, .or::after { content: ''; flex: 1; border-top: 2.5px dotted var(--ink-2); }
.otp { font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 26px; letter-spacing: .3em; text-align: center; width: 100%; font-variant-numeric: tabular-nums; }
.sec-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 2.5px dotted color-mix(in srgb, var(--ink-2) 50%, transparent); flex-wrap: wrap; }
.sec-row:last-of-type { border-bottom: 0; }
.sec-row .grow { flex: 1; min-width: 0; }
.sec-row .meta { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.on-tag, .off-tag { display: inline-block; white-space: nowrap; font-size: 11px; font-weight: 800; border-radius: 999px; padding: 1px 9px; border: 2px solid; }
.on-tag { border-color: #3a2b5e; color: #3a2b5e; background: var(--melon); }
.off-tag { border-color: var(--ink-2); color: var(--ink-2); }
.pk-list { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 6px; width: 100%; }
.pk-list li { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; background: var(--paper-2); border-radius: 999px; padding: 4px 6px 4px 14px; }
.pk-list li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dialog { border: 3px solid var(--line); border-radius: 26px; background: var(--paper); color: var(--ink); width: min(440px, calc(100% - 32px)); padding: 22px; box-shadow: var(--pop-lg); }
dialog::backdrop { background: color-mix(in srgb, #3a2b5e 55%, transparent); }
dialog h3 { margin: 0 0 10px; font-family: 'Mochiy Pop One', 'M PLUS Rounded 1c', sans-serif; font-weight: 800; font-size: 18px; }
.qr { display: grid; place-items: center; background: #fff; border: 3px solid #3a2b5e; border-radius: 18px; padding: 8px; margin: 12px auto; width: max-content; }
.qr svg { display: block; width: 200px; height: 200px; }
.secret { font-family: ui-monospace, monospace; font-size: 14px; font-weight: 700; word-break: break-all; background: var(--paper-2); padding: 10px 12px; border-radius: 12px; user-select: all; text-align: center; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-family: ui-monospace, monospace; font-size: 15px; font-weight: 700; background: var(--paper-2); padding: 14px; border-radius: 16px; margin: 12px 0; user-select: all; }

@media (max-width: 480px) {
  #me-chip span { display: none; }
  .room-head { font-size: 14px; }
  .title span { width: 44px; height: 44px; font-size: 23px; border-radius: 13px; }
  .fuda { width: 140px; height: 140px; border-radius: 34px; }
  .fuda span { font-size: 78px; }
  .answer input { font-size: 19px; }
  .card { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .fuda.pop { animation: none; }
  .btn, .timer div { transition: none; }
}

/* 登録せずに見る */
.mode-note { margin: -4px 0 12px; }
.watch-only { margin-top: 0; }
.watch-only form { flex-wrap: nowrap; }
