:root {
  --bg: #eef3f8;
  --ink: #182231;
  --muted: #667388;
  --line: #c9d4e3;
  --panel: #ffffff;
  --empty: #d9e2ef;
  --cell: #fbfdff;
  --cell-active: #ffffff;
  --cursor: #f4b000;
  --solved: #1976d2;
  --prefilled: #0f6b3a;
  --card-used: #a5acb8;
  --chat-other: #ffffff;
  --chat-self: #d9ecff;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.fullscreen-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 34, 49, 0.74);
  color: #fff;
  cursor: pointer;
}

.fullscreen-gate-card {
  width: min(520px, 92vw);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: rgba(24, 34, 49, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
  text-align: center;
}

.fullscreen-gate-kicker {
  display: block;
  margin-bottom: 10px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #bfe6ff;
}

.fullscreen-gate-card strong {
  display: block;
  font-size: clamp(1.7rem, 5vw, 2.8rem);
  line-height: 1.2;
}

.fullscreen-gate-card span:last-child {
  display: block;
  margin-top: 14px;
  color: #eef6ff;
  font-weight: 700;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(90deg, rgba(26, 78, 130, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(26, 78, 130, 0.08) 1px, transparent 1px),
    #eef3f8;
  background-size: 36px 36px;
}

.login-panel {
  width: min(760px, 94vw);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 20px 70px rgba(42, 64, 94, 0.18);
}

.login-panel h1 {
  margin: 0 0 26px;
  font-size: 64px;
  line-height: 1;
  letter-spacing: 0;
}

.auth-status {
  margin-top: 8px;
  font-size: 22px;
  font-weight: 700;
  color: var(--muted);
  min-height: 32px;
}

.auth-identity {
  margin-top: 18px;
  display: grid;
  gap: 8px;
}

.auth-name-line {
  font-size: 58px;
  font-weight: 800;
  line-height: 1.12;
}

.auth-error {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fdecea;
  color: #b91c1c;
  font-weight: 700;
}

.auth-actions {
  margin-top: 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.primary-button {
  min-width: 126px;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 8px;
  background: #1976d2;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.login-panel .primary-button {
  font-size: 26px;
}

.ghost-button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.ghost-button:hover {
  background: #f1f5fb;
}

.portal-return-button {
  min-height: 48px;
  padding: 8px 18px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #f4b000;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.25;
  cursor: pointer;
}

.portal-return-button:hover {
  background: #ffd76a;
}

.game-screen {
  width: 100vw;
  height: 100vh;
  padding-top: var(--top-bar-h, 78px);
  display: flex;
  flex-direction: column;
}

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.player-badge {
  min-width: 0;
  font-size: 24px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-badge {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-weight: 900;
  color: #0f4f9a;
}

.score-badge .score-count {
  font-size: 58px;
  line-height: 1;
}

.score-badge .rank-count {
  font-size: 28px;
  color: var(--ink);
}

.end-button {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  max-width: min(390px, calc(100vw - 32px));
  min-height: 44px;
  padding: 8px 16px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #f4b000;
  color: var(--ink);
  font-weight: 900;
  line-height: 1.25;
  cursor: pointer;
}

.end-button:hover {
  background: #ffd76a;
}

.game-layout {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.board-pane {
  min-width: 0;
  height: 100%;
  padding: 14px 16px 16px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 88px;
  gap: 12px;
  border-right: 1px solid var(--line);
}

.crossword-grid {
  --grid-size: min(calc(50vw - 36px), calc(100vh - var(--top-bar-h, 78px) - 120px));
  --cell-size: calc(var(--grid-size) / 10);
  align-self: center;
  justify-self: center;
  width: var(--grid-size);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  border: 2px solid #8393aa;
  background: #8393aa;
  gap: 1px;
  user-select: none;
  touch-action: none;
  cursor: grab;
}

.crossword-grid.is-dragging {
  cursor: grabbing;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background: var(--empty);
  color: var(--ink);
  font-weight: 900;
  font-size: calc(var(--cell-size) * 0.55);
  line-height: 1;
  overflow: hidden;
}

.cell.is-open {
  background: var(--cell);
}

.cell.has-input {
  background: var(--cell-active);
}

.cell.is-solved {
  color: var(--solved);
}

.cell.is-prefilled {
  color: var(--prefilled);
}

.cell.is-removable {
  cursor: pointer;
}

.cell.is-cursor::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 4px solid var(--cursor);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.95);
  pointer-events: none;
}

.cell.is-start::before {
  content: attr(data-label);
  position: absolute;
  top: 2px;
  left: 3px;
  color: #516074;
  font-size: calc(var(--cell-size) * 0.22);
  line-height: 1;
  font-weight: 800;
}

.cell.is-solved::before {
  color: #145da2;
}

.cell.is-prefilled::before {
  color: var(--prefilled);
}

.cursor-guide {
  position: relative;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.guide-arrow {
  position: absolute;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid #f4b000;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: #0f4f9a;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(24, 34, 49, 0.22);
}

.guide-up {
  bottom: calc(100% + 4px);
}

.guide-right {
  left: calc(100% + 4px);
}

.guide-down {
  top: calc(100% + 4px);
}

.guide-left {
  right: calc(100% + 4px);
}

.guide-text {
  position: absolute;
  top: calc(100% + 36px);
  left: 50%;
  width: max-content;
  max-width: 240px;
  transform: translateX(-50%);
  padding: 5px 10px;
  border: 1px solid #f4b000;
  border-radius: 8px;
  background: #fff8de;
  color: #182231;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(24, 34, 49, 0.18);
}

.hint-box {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.45;
  overflow: hidden;
}

.hint-text {
  display: inline;
}

.side-pane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
}

.card-pane {
  min-width: 0;
  min-height: 0;
  padding: 14px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
}

.card-grid {
  --card-size: 56px;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(6, var(--card-size));
  grid-auto-rows: var(--card-size);
  justify-content: center;
  align-content: start;
  gap: 7px;
}

.letter-card {
  width: var(--card-size);
  height: var(--card-size);
  border: 1px solid #b5c2d3;
  border-radius: 8px;
  background: #fff;
  color: #1e293b;
  font-size: calc(var(--card-size) * 0.5);
  font-weight: 900;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 3px 0 #d5deea;
  user-select: none;
}

.letter-card:hover {
  border-color: #1976d2;
}

.letter-card.is-used {
  color: var(--card-used);
  background: #f1f3f6;
  box-shadow: none;
}

.letter-card.is-correct {
  color: var(--solved);
  background: #eef7ff;
  box-shadow: none;
  cursor: default;
}

.letter-card.is-used.is-movable {
  cursor: pointer;
}

.letter-card:disabled {
  opacity: 1;
  cursor: default;
}

.letter-card.is-empty {
  cursor: default;
  border-style: dashed;
  background: transparent;
  box-shadow: none;
}

.ranking-pane {
  min-width: 0;
  min-height: 0;
  padding: 14px;
  background: #f7f9fc;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.ranking-title {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
  color: #0f4f9a;
}

.ranking-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
}

.ranking-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 700;
}

.ranking-item.is-self {
  background: var(--chat-self);
  border-color: #9dccff;
}

.ranking-rank {
  font-size: 20px;
  font-weight: 900;
  color: #0f4f9a;
  text-align: center;
  white-space: nowrap;
}

.ranking-name {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-display-name {
  color: var(--prefilled);
  font-weight: 800;
}

.ranking-no {
  margin-left: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ranking-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.ranking-count {
  font-size: 18px;
  font-weight: 900;
  color: #0f4f9a;
  line-height: 1;
}

.ranking-time {
  font-size: 11px;
  color: var(--muted);
  line-height: 1;
}

.ranking-loading {
  list-style: none;
  padding: 16px 12px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
}

.move-help,
.term-overlay {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(13, 23, 38, 0.56);
}

.move-help[hidden],
.term-overlay[hidden],
.game-screen[hidden],
.login-screen[hidden] {
  display: none;
}

.move-help-panel {
  width: min(520px, 92vw);
  padding: 30px;
  border-radius: 8px;
  background: #fff;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.move-help-panel p {
  margin: 0 0 24px;
  font-size: 44px;
  font-weight: 900;
}

.term-card {
  width: min(980px, 94vw);
  max-height: 90vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 22px;
  padding: 44px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.32);
}

.term-card h2 {
  margin: 0;
  color: #0f4f9a;
  font-size: 78px;
  line-height: 1.02;
  letter-spacing: 0;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.term-card p {
  margin: 0;
  overflow-y: auto;
  color: #283548;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.65;
}

.term-card .primary-button {
  justify-self: end;
  font-size: 24px;
}

.confetti-layer {
  position: fixed;
  z-index: 55;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 18px;
  border-radius: 2px;
  opacity: 0.92;
  animation: confetti-fall 1200ms ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, -20px, 0) rotate(0deg);
  }

  100% {
    transform: translate3d(var(--drift), calc(100vh + 70px), 0) rotate(var(--spin));
  }
}

.flying-card {
  position: fixed;
  z-index: 80;
  display: grid;
  place-items: center;
  border: 1px solid #1976d2;
  border-radius: 8px;
  background: #fff;
  color: #1e293b;
  font-weight: 900;
  box-shadow: 0 14px 30px rgba(25, 118, 210, 0.28);
  pointer-events: none;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .game-screen {
    min-height: 100vh;
    height: auto;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .board-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .crossword-grid {
    --grid-size: min(calc(100vw - 32px), calc(100vh - var(--top-bar-h, 78px) - 120px));
  }

  .side-pane {
    min-height: 82vh;
  }
}

@media (max-width: 680px) {
  .side-pane {
    grid-template-columns: 1fr;
  }

  .top-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
  }

  .score-badge .score-count {
    font-size: 34px;
  }

  .login-panel h1 {
    font-size: 42px;
  }

  .auth-name-line {
    font-size: 36px;
  }

  .player-badge {
    font-size: 18px;
  }

  .score-badge .rank-count {
    font-size: 20px;
  }

  .hint-box {
    font-size: 16px;
  }

  .move-help-panel p {
    font-size: 30px;
  }

  .term-card {
    padding: 24px;
  }

  .term-card h2 {
    font-size: 44px;
  }

  .term-card p {
    font-size: 18px;
  }
}

/* ---- 単独版: ニックネーム変更 UI ---- */
.player-badge {
  cursor: pointer;
}

.ranking-display-name.is-editable {
  cursor: pointer;
  text-decoration: underline dotted;
}
