:root {
  --ink:      #1b1116;
  --ink-2:    #251820;
  --ink-3:    #32222b;
  --edge:     #4a3340;
  --bone:     #efe6d4;
  --bone-dim: #a8998a;
  --rose:     #c0334a;
  --rose-deep:#7d1f2e;
  --brass:    #d9a441;
  --ash:      #93818c;

  --display: "Zen Old Mincho", "Hiragino Mincho ProN", serif;
  --body: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  --mono: "DM Mono", ui-monospace, "SFMono-Regular", monospace;

  --disc: 58px;
  --peek: 7px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 80% at 50% -10%, #3a2430 0%, transparent 60%),
    var(--ink);
  color: var(--bone);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- */
/* 共通パーツ                                                          */
/* ---------------------------------------------------------------- */

.btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--ink-2);
  color: var(--bone);
  font-weight: 500;
  letter-spacing: .04em;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover:not(:disabled) { background: var(--ink-3); border-color: var(--brass); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.btn-primary {
  background: var(--rose-deep);
  border-color: var(--rose);
  font-weight: 700;
}
.btn-primary:hover:not(:disabled) { background: var(--rose); border-color: var(--rose); }

.btn-ghost { width: auto; background: none; border-color: transparent; color: var(--ash); }
.btn-ghost:hover:not(:disabled) { background: var(--ink-2); border-color: var(--edge); color: var(--bone); }
.btn-sm { padding: 6px 10px; font-size: 13px; }

.mono { font-family: var(--mono); letter-spacing: .12em; }

.screen { display: block; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- */
/* 入口                                                              */
/* ---------------------------------------------------------------- */

.entry-inner {
  max-width: 380px;
  margin: 0 auto;
  padding: 14vh 20px 40px;
}

.brand { text-align: center; margin-bottom: 34px; }

/* 署名的要素: 積み上がった円盤を横から見た姿 */
.brand-mark {
  width: 88px; height: 62px;
  margin: 0 auto 18px;
  position: relative;
}
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--bone) 55%, var(--bone-dim));
  box-shadow: 0 2px 0 #6d6053;
}
.brand-mark::before { top: 30px; }
.brand-mark::after  { top: 16px; }
.brand-mark span {
  position: absolute; top: 2px; left: 0; right: 0; height: 16px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--bone) 55%, var(--bone-dim));
  box-shadow: 0 2px 0 #6d6053, 0 6px 16px rgba(0,0,0,.5);
}

.brand-title {
  font-family: var(--display);
  font-weight: 900;
  font-size: 40px;
  letter-spacing: .3em;
  margin: 0 0 8px;
  text-indent: .3em;
}
.brand-sub { margin: 0; color: var(--ash); font-size: 13.5px; }

.panel {
  border: 1px solid var(--ink-3);
  border-radius: 4px;
  background: rgba(37, 24, 32, .72);
  padding: 22px 20px;
}

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 12px;
  color: var(--ash);
  letter-spacing: .1em;
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--ink);
  outline: none;
}
.field input:focus { border-color: var(--brass); }
#room-input { text-transform: uppercase; }

.spectate-toggle {
  display: flex; align-items: center; gap: 7px;
  margin: -4px 0 14px;
  font-size: 12.5px; color: var(--ash);
}
.spectate-reveal { margin: -10px 0 14px 22px; color: var(--rose); }

.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0;
  color: var(--ash); font-size: 12px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--ink-3);
}

.entry-note { text-align: center; color: var(--ash); font-size: 12px; margin-top: 18px; }

/* ---------------------------------------------------------------- */
/* 卓のヘッダー                                                        */
/* ---------------------------------------------------------------- */

.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ink-3);
  background: rgba(27, 17, 22, .9);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}

.room-code {
  padding: 5px 10px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--ink-2);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: .18em;
  color: var(--brass);
  cursor: pointer;
}
.room-code:hover { border-color: var(--brass); }

.phase-line { flex: 1; font-size: 13px; color: var(--ash); min-width: 0; }
.phase-line b { color: var(--bone); font-weight: 500; }
.spectator-note {
  border: none; background: none; padding: 0;
  color: var(--ash);
  font: inherit;
  text-decoration: underline dotted;
  cursor: pointer;
}
.spectator-note:hover { color: var(--brass); }

/* ---------------------------------------------------------------- */
/* 席                                                                */
/* ---------------------------------------------------------------- */

.seats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  padding: 16px 14px;
  max-width: 1080px;
  margin: 0 auto;
}

.seat {
  border: 1px solid var(--ink-3);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(51,34,43,.5), rgba(37,24,32,.5));
  padding: 12px 14px 14px;
  min-height: 168px;
  display: flex;
  flex-direction: column;
  transition: border-color .2s, box-shadow .2s;
}
.seat.is-turn { border-color: var(--brass); box-shadow: 0 0 0 1px rgba(217,164,65,.25); }
.seat.is-you  { background: linear-gradient(180deg, rgba(61,40,51,.6), rgba(37,24,32,.6)); }
.seat.is-out  { opacity: .4; }
.seat.is-challenger { border-color: var(--rose); }

.seat-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.seat-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .06em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seat-tag {
  font-size: 10.5px; letter-spacing: .1em;
  padding: 1px 6px; border-radius: 2px;
  border: 1px solid currentColor;
  flex: none;
}
.tag-turn { color: var(--brass); }
.tag-chal { color: var(--rose); }
.tag-off  { color: var(--ash); }

.seat-meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 11.5px; color: var(--ash);
  margin-bottom: 10px;
}
.pips { display: inline-flex; gap: 3px; }
.pip { width: 7px; height: 7px; border-radius: 50%; background: var(--edge); }
.pip.on { background: var(--bone-dim); }
.pip.win { background: var(--brass); }

.seat-field { flex: 1; display: flex; align-items: flex-end; gap: 16px; }

/* 積み山: 円盤の縁が少しずつ覗く */
.stack {
  position: relative;
  width: var(--disc);
  flex: none;
  cursor: default;
}
.stack.flippable { cursor: pointer; }
.stack.flippable:hover .disc-back { border-color: var(--brass); }
.stack-slot { position: relative; height: calc(var(--disc) + var(--peek) * 4); }
.stack .disc {
  position: absolute;
  left: 0;
  bottom: 0;
}
.stack-empty {
  height: var(--disc);
  border: 1px dashed var(--edge);
  border-radius: 50%;
  width: var(--disc);
}

.revealed { display: flex; flex-wrap: wrap; gap: 5px; align-items: flex-end; }

/* 全公開モードの観覧者にだけ見える、まだ出していない手札 */
.reveal-hand {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--edge);
}

/* 円盤そのもの */
.disc {
  width: var(--disc); height: var(--disc);
  border-radius: 50%;
  display: grid; place-items: center;
  user-select: none;
  flex: none;
}
.disc-back {
  background: radial-gradient(circle at 38% 32%, #f6efe0, #d9cdb8 70%, #b6a993);
  border: 1px solid #8b7f6d;
  box-shadow: 0 2px 0 #6d6053, 0 4px 10px rgba(0,0,0,.45);
}
.disc-back::after {
  content: "";
  width: 56%; height: 56%;
  border-radius: 50%;
  border: 1px solid rgba(109,96,83,.55);
}
.disc-rose {
  background: radial-gradient(circle at 38% 32%, #f6efe0, #ddd0ba 75%);
  border: 1px solid #8b7f6d;
  box-shadow: 0 2px 0 #6d6053;
}
.disc-skull {
  background: radial-gradient(circle at 38% 32%, #3b2028, #1a0d11 80%);
  border: 1px solid var(--rose-deep);
  box-shadow: 0 2px 0 #12080b, 0 0 18px rgba(192,51,74,.45);
}
.disc svg { width: 62%; height: 62%; display: block; }
.disc.sm { width: 34px; height: 34px; }

.just-flipped { animation: flip .42s cubic-bezier(.2,.7,.3,1) both; }
@keyframes flip {
  from { transform: rotateY(90deg) scale(.85); opacity: 0; }
  to   { transform: rotateY(0) scale(1); opacity: 1; }
}

body.skull-hit { animation: shake .45s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

/* ---------------------------------------------------------------- */
/* 操作パネル                                                         */
/* ---------------------------------------------------------------- */

.control {
  position: sticky; bottom: 0;
  border-top: 1px solid var(--ink-3);
  background: rgba(27, 17, 22, .94);
  backdrop-filter: blur(8px);
  padding: 14px;
  max-width: 1080px;
  margin: 0 auto;
}

.prompt { font-size: 14px; margin: 0 0 10px; }
.prompt b { color: var(--brass); font-weight: 500; }
.prompt-quiet { color: var(--ash); }

.hand { display: flex; gap: 10px; flex-wrap: wrap; }
.hand button {
  border: none; background: none; padding: 0; cursor: pointer; border-radius: 50%;
  transition: transform .12s;
}
.hand button:hover:not(:disabled) { transform: translateY(-5px); }
.hand button:disabled { cursor: not-allowed; opacity: .5; }
.hand button:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  min-width: 40px;
  padding: 7px 10px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--ink-2);
  font-family: var(--mono);
  font-size: 14px;
  cursor: pointer;
}
.chip:hover:not(:disabled) { border-color: var(--brass); color: var(--brass); }
.chip:disabled { opacity: .28; cursor: not-allowed; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row .btn { width: auto; min-width: 110px; }

.result {
  border-left: 3px solid var(--edge);
  padding: 2px 0 2px 12px;
  margin: 0 0 12px;
}
.result.ok   { border-color: var(--brass); }
.result.bad  { border-color: var(--rose); }
.result h3 { font-family: var(--display); font-size: 18px; margin: 0 0 2px; letter-spacing: .06em; }
.result p  { margin: 0; font-size: 13px; color: var(--ash); }

.roster { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; padding: 0; list-style: none; }
.roster li {
  font-size: 13px;
  padding: 4px 10px;
  border: 1px solid var(--ink-3);
  border-radius: 99px;
}
.roster li.host { border-color: var(--brass); color: var(--brass); }

/* ---------------------------------------------------------------- */
/* 記録                                                              */
/* ---------------------------------------------------------------- */

.log-panel {
  position: fixed; inset: auto 0 0 0;
  max-height: 62vh;
  background: var(--ink-2);
  border-top: 1px solid var(--edge);
  z-index: 30;
  display: flex; flex-direction: column;
}
.log-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--ink-3);
}
.log-head h2 { font-family: var(--display); font-size: 15px; margin: 0; letter-spacing: .12em; }
.log-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.log-list {
  margin: 0; padding: 10px 16px 20px 30px;
  overflow-y: auto; font-size: 13px; color: var(--ash);
}
.log-list li { padding: 2px 0; }
.log-list li::marker { color: var(--edge); font-family: var(--mono); font-size: 11px; }

.export-picker { padding: 12px 16px 16px; overflow-y: auto; }
.link-btn {
  border: none; background: none;
  color: var(--brass);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0 0 0 4px;
}
.link-btn:hover { color: var(--bone); }
.export-match-list {
  margin: 10px 0 16px; padding: 0;
  list-style: none;
  display: flex; flex-direction: column; gap: 2px;
}
.export-match-list li {
  border: 1px solid var(--ink-3);
  border-radius: 3px;
  margin-bottom: 6px;
}
.export-match-list label {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
.export-match-name { font-weight: 500; flex: none; }
.export-match-time { color: var(--ash); font-size: 12px; font-family: var(--mono); }
.export-match-time.pending { color: var(--brass); }

/* ---------------------------------------------------------------- */
/* トースト                                                           */
/* ---------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--rose-deep);
  border: 1px solid var(--rose);
  border-radius: 3px;
  padding: 10px 16px;
  font-size: 13.5px;
  z-index: 50;
  max-width: min(92vw, 420px);
  animation: rise .2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (max-width: 420px) {
  :root { --disc: 48px; --peek: 6px; }
  .brand-title { font-size: 32px; }
  .seats { grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; }
  .seat { min-height: 150px; padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 自分の山：中身は見えるが「まだ伏せてある」ことが分かる扱い */
.stack .disc.peek,
.reveal-hand .disc.peek {
  opacity: .5;
  border-style: dashed;
  border-color: var(--edge);
  filter: saturate(.55);
}
.seat.is-you .stack.flippable .disc.peek { opacity: .75; }

/* ---------------------------------------------------------------- */
/* 招待リンク                                                          */
/* ---------------------------------------------------------------- */

.invite {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 14px 0;
}
.invite input {
  width: 100%;
  margin-top: 6px;
  padding: 9px 11px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--ink);
  color: var(--brass);
  font-size: 12.5px;
  letter-spacing: .02em;
}

/* ---------------------------------------------------------------- */
/* 手札公開の許可バナー                                                  */
/* ---------------------------------------------------------------- */

.consent-banner {
  max-width: 1080px;
  margin: 10px auto 0;
  padding: 0 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.consent-row {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--rose);
  border-radius: 4px;
  background: rgba(125, 31, 46, .22);
  font-size: 13.5px;
}
.consent-row .row { flex: none; }
.consent-row .row .btn { width: auto; }

/* ---------------------------------------------------------------- */
/* 流れるコメント（ニコニコ風）                                          */
/* ---------------------------------------------------------------- */

.comments-fly {
  position: fixed;
  top: 100px;
  left: 0;
  right: 0;
  height: 42vh;
  pointer-events: none;
  overflow: hidden;
  z-index: 15;
}

.comment-fly {
  position: absolute;
  right: -8%;
  top: 0;
  white-space: nowrap;
  font-family: var(--body);
  font-weight: 500;
  font-size: 16px;
  color: var(--bone);
  text-shadow: 0 1px 3px rgba(0,0,0,.85), 0 0 10px rgba(0,0,0,.5);
  animation-name: comment-fly-rtl;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  will-change: transform;
}
.comment-fly.vertical {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 15px;
  right: auto;
  top: auto;
  bottom: -12%;
  animation-name: comment-fly-btt;
}
/* 横書き：右から左へ */
@keyframes comment-fly-rtl {
  from { transform: translateX(0); }
  to   { transform: translateX(-116vw); }
}
/* 縦書き：下から上へ */
@keyframes comment-fly-btt {
  from { transform: translateY(0); }
  to   { transform: translateY(-58vh); }
}

@media (prefers-reduced-motion: reduce) {
  .comment-fly { animation: none !important; display: none; }
}

/* ---------------------------------------------------------------- */
/* チャット                                                            */
/* ---------------------------------------------------------------- */

.chat-panel {
  position: fixed; inset: auto 0 0 0;
  max-height: 62vh;
  background: var(--ink-2);
  border-top: 1px solid var(--edge);
  z-index: 30;
  display: flex; flex-direction: column;
}
.chat-list {
  margin: 0; padding: 10px 16px;
  overflow-y: auto; flex: 1;
  list-style: none;
  font-size: 13.5px;
}
.chat-list li { padding: 4px 0; display: flex; gap: 8px; align-items: baseline; }
.chat-list li.is-you .chat-name { color: var(--brass); }
.chat-name { flex: none; font-weight: 700; color: var(--ash); }
.chat-text { word-break: break-word; flex: 1; }
.chat-del {
  flex: none;
  border: none; background: none;
  color: var(--ash);
  font-size: 15px;
  line-height: 1;
  padding: 2px 5px;
  cursor: pointer;
  border-radius: 3px;
  opacity: .5;
}
.chat-del:hover { opacity: 1; color: var(--rose); background: var(--ink-3); }

/* 常時表示のチャット入力バー（ヘッダーのすぐ下） */
.chat-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  max-width: 1080px;
  margin: 0 auto;
  border-bottom: 1px solid var(--ink-3);
}
.chat-bar input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--edge);
  border-radius: 3px;
  background: var(--ink);
  outline: none;
  font-size: 13.5px;
}
.chat-bar input[type="text"]:focus { border-color: var(--brass); }
.chat-vertical {
  flex: none;
  display: flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--ash);
  white-space: nowrap;
}
.chat-bar .btn { width: auto; }

.chat-export-toggle {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--ash);
  white-space: nowrap;
  margin-right: 6px;
}

@media (max-width: 420px) {
  .comments-fly { top: 88px; height: 36vh; }
  .comment-fly { font-size: 14px; }
}
