:root {
  --bg: #0b1020;
  --bg-soft: #141b33;
  --card: #161e3a;
  --card-2: #1c264a;
  --line: #2a3566;
  --text: #e8ecff;
  --muted: #94a0c8;
  --accent: #00e6c3;
  --accent-2: #5b8cff;
  --eat: #ff5c8a;
  --bite: #ffc24b;
  --danger: #ff6b6b;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(1200px 800px at 50% -10%, #16224a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, -apple-system,
    "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.logo {
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 3px;
  margin: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo .amp {
  margin: 0 4px;
  -webkit-text-fill-color: var(--bite);
  color: var(--bite);
}
.logo-sub {
  display: block;
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--muted);
  font-weight: 600;
  -webkit-text-fill-color: var(--muted);
}
.hl {
  color: var(--accent);
}

.conn {
  font-size: 12px;
  transition: color 0.3s;
}
.conn--off {
  color: #5b6486;
}
.conn--connecting {
  color: var(--bite);
}
.conn--on {
  color: var(--accent);
}

.screen {
  animation: fade 0.25s ease;
}
.hidden {
  display: none !important;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.lead {
  color: var(--muted);
  text-align: center;
  margin: 0 0 18px;
}

.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card.center {
  text-align: center;
}
.card--accent {
  border-color: var(--accent);
  box-shadow: 0 10px 30px rgba(0, 230, 195, 0.12), var(--shadow);
}
.btn--big {
  padding: 18px 16px;
  font-size: 18px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.field {
  display: block;
  margin-bottom: 14px;
}
.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input[type="text"],
.field select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}
.field input[type="text"]:focus,
.field select:focus {
  border-color: var(--accent-2);
}
.field-row {
  display: flex;
  gap: 14px;
  align-items: flex-end;
}
.field-row .field {
  flex: 1;
}
.field--check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
}
.field--check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.field--check span {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}

.btn {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  padding: 13px 16px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.2s, background 0.2s, opacity 0.2s;
}
.btn:active {
  transform: translateY(1px) scale(0.99);
}
.btn:hover {
  filter: brightness(1.08);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn--primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #06121a;
  border: none;
}
.btn--ghost {
  background: transparent;
}
.btn--text {
  background: transparent;
  border: none;
  color: var(--muted);
  width: auto;
  margin-top: 12px;
}

.divider {
  text-align: center;
  color: var(--muted);
  position: relative;
  margin: 6px 0 16px;
  font-size: 13px;
}
.divider::before,
.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--line);
}
.divider::before {
  left: 0;
}
.divider::after {
  right: 0;
}

.rules {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  color: var(--muted);
  font-size: 14px;
}
.rules summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
}
.rules ol {
  padding-left: 20px;
  line-height: 1.7;
}
.hit {
  color: var(--eat);
}
.blow {
  color: var(--bite);
}

.muted {
  color: var(--muted);
}

/* 待機画面 */
.roomcode {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 44px;
  letter-spacing: 10px;
  font-weight: 800;
  color: var(--accent);
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 16px;
  margin: 14px 0;
  user-select: all;
}
.share-row {
  display: flex;
  gap: 10px;
  margin: 8px 0;
}
.spinner {
  width: 34px;
  height: 34px;
  margin: 18px auto 6px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 数字入力 */
.entry-display {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 16px;
}
.slot {
  width: 52px;
  height: 64px;
  border-radius: 12px;
  background: var(--bg);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, monospace;
  font-size: 32px;
  font-weight: 800;
}
.slot.filled {
  border-color: var(--accent-2);
  color: var(--text);
}
.slot.cursor {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 230, 195, 0.15);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.key {
  padding: 16px 0;
  font-size: 22px;
  font-weight: 800;
  font-family: ui-monospace, monospace;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.06s, background 0.15s, opacity 0.15s;
}
.key:active {
  transform: translateY(1px) scale(0.96);
}
.key:hover:not(:disabled) {
  background: var(--line);
}
.key:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.entry-actions {
  display: flex;
  gap: 10px;
}
.entry-actions .btn {
  flex: 1;
}
.entry-actions .btn--primary {
  flex: 2;
}

.status {
  min-height: 20px;
  text-align: center;
  color: var(--bite);
  font-size: 14px;
  margin: 10px 0 0;
}

/* 対戦画面 */
.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.player-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 14px;
  font-weight: 700;
  max-width: 38%;
  overflow: hidden;
}
.player-chip .nm {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4a5384;
  flex: none;
}
.player-chip.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 230, 195, 0.18);
}
.player-chip.active .dot {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.player-chip.off .dot {
  background: var(--danger);
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}
.turn-banner {
  flex: 1;
  text-align: center;
  font-weight: 800;
  font-size: 15px;
  color: var(--accent);
}
.turn-banner.wait {
  color: var(--muted);
}

.boards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.board {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  min-height: 120px;
}
.board h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text);
}
.board h3 small {
  color: var(--muted);
  font-weight: 500;
}
.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 240px;
  overflow-y: auto;
}
.history li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  animation: pop 0.2s ease;
}
@keyframes pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
}
.history .num {
  font-family: ui-monospace, monospace;
  font-size: 18px;
  letter-spacing: 2px;
  font-weight: 700;
}
.history .res {
  display: flex;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}
.history .res .e {
  color: var(--eat);
}
.history .res .b {
  color: var(--bite);
}
.history li.win {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.history .empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 14px 0;
}

/* アイテム（特殊コール） */
.items-wrap {
  margin-bottom: 12px;
}
.items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.items-toggle {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}
.items-toggle:hover {
  background: var(--line);
}
.items-budget {
  font-size: 13px;
  color: var(--bite);
  font-weight: 700;
}
.items-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.items-cat {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 1px;
  padding: 6px 4px 2px;
}
.item-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: transform 0.06s, background 0.15s, opacity 0.15s;
}
.item-btn .ic {
  font-size: 18px;
  line-height: 1;
}
.item-btn b {
  font-size: 11px;
  letter-spacing: 0.3px;
}
.item-btn small {
  font-size: 9px;
  color: var(--muted);
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item-btn:active {
  transform: translateY(1px) scale(0.97);
}
.item-attack {
  border-color: rgba(255, 92, 138, 0.5);
}
.item-attack b {
  color: var(--eat);
}
.item-action {
  border-color: rgba(255, 194, 75, 0.6);
}
.item-action b {
  color: var(--bite);
}
.item-defense {
  border-color: rgba(0, 230, 195, 0.5);
}
.item-defense b {
  color: var(--accent);
}
.item-btn:hover:not(:disabled) {
  background: var(--line);
}
.item-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.item-btn.used b {
  text-decoration: line-through;
  color: var(--muted);
}

.param-prompt {
  background: var(--bg);
  border: 1px solid var(--bite);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.prompt-label {
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--bite);
  font-weight: 700;
}
.prompt-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.prompt-row .btn {
  width: auto;
  flex: 1;
}

.effects-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.effects-bar:empty {
  display: none;
}
.effect-tag {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(0, 230, 195, 0.1);
  border: 1px solid rgba(0, 230, 195, 0.4);
  border-radius: 999px;
  padding: 4px 10px;
}

.intel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.intel:empty {
  display: none;
}
.intel-card {
  background: var(--bg);
  border: 1px solid var(--bite);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
}
.intel-card .label {
  color: var(--bite);
  font-weight: 800;
  margin-right: 8px;
  font-size: 11px;
}
.intel-card .val {
  font-family: ui-monospace, monospace;
  font-weight: 800;
  letter-spacing: 3px;
  font-size: 16px;
}
.intel-card .hi {
  color: var(--eat);
}
.intel-card .lo {
  color: var(--accent-2);
}
.intel-card.blocked {
  border-color: var(--danger);
  opacity: 0.8;
}
.history .res .ob {
  color: var(--muted);
  font-style: italic;
}

.double-indicator {
  text-align: center;
  font-weight: 800;
  color: var(--bite);
  background: rgba(255, 194, 75, 0.12);
  border: 1px solid var(--bite);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 12px;
  animation: pulse 1.2s ease-in-out infinite;
}

/* 結果 */
.result-emoji {
  font-size: 56px;
  margin-bottom: 6px;
}
.reveal {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin: 16px 0;
}
.reveal > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.reveal span {
  font-size: 12px;
}
.reveal b {
  font-family: ui-monospace, monospace;
  font-size: 28px;
  letter-spacing: 3px;
  color: var(--accent);
}

/* チャット */
.chat {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
}
.chat-toggle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #06121a;
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow);
  position: relative;
}
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--eat);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 6px;
  font-weight: 800;
}
.chat-box {
  position: absolute;
  right: 0;
  bottom: 64px;
  width: min(320px, 80vw);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-log {
  height: 240px;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  max-width: 80%;
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 14px;
  word-break: break-word;
}
.chat-msg.mine {
  align-self: flex-end;
  background: var(--accent-2);
  color: #06121a;
}
.chat-msg.theirs {
  align-self: flex-start;
  background: var(--bg-soft);
}
.chat-msg .who {
  display: block;
  font-size: 11px;
  opacity: 0.7;
  margin-bottom: 2px;
}
.chat-form {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line);
}
.chat-form input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}
.chat-form .btn {
  width: auto;
  padding: 9px 14px;
}

/* トースト */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 90vw;
  text-align: center;
  font-size: 14px;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 480px) {
  .roomcode {
    font-size: 34px;
    letter-spacing: 6px;
  }
  .slot {
    width: 44px;
    height: 56px;
    font-size: 26px;
  }
  .key {
    padding: 14px 0;
    font-size: 20px;
  }
  .boards {
    grid-template-columns: 1fr;
  }
}
