/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-main: #e0f7fa;
  --bg-card: rgba(255, 255, 255, 0.65);
  --bg-card-hover: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.5);
  --accent: #00acc1;
  --accent-glow: rgba(0, 172, 193, 0.4);
  --hit-color: #d81b60;
  --blow-color: #2e7d32;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --digit-active: rgba(0, 172, 193, 0.25);
  --digit-filled: rgba(0, 172, 193, 0.12);
  --slot-selected: #00acc1;
  --slot-default: rgba(30, 41, 59, 0.15);
  --success-bg: rgba(81, 207, 102, 0.2);
  --success-border: rgba(81, 207, 102, 0.5);
  --font-main: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

body {
  font-family: var(--font-main);
  background: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* Animated background gradient */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 400px at 20% 20%, rgba(0, 188, 212, 0.2), transparent),
    radial-gradient(ellipse 500px 500px at 80% 80%, rgba(255, 107, 157, 0.1), transparent),
    radial-gradient(ellipse 400px 300px at 50% 50%, rgba(81, 207, 102, 0.1), transparent);
  z-index: -1;
  animation: bgShift 20s ease-in-out infinite alternate;
}
@keyframes bgShift {
  0%   { transform: scale(1) translate(0, 0); }
  100% { transform: scale(1.1) translate(-20px, 10px); }
}

/* ===== Header ===== */
.header {
  text-align: center;
  padding: 2.5rem 1rem 1rem;
}
.header h1 {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #00838f 0%, #00bcd4 50%, #4dd0e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titleGlow 3s ease-in-out infinite alternate;
}
@keyframes titleGlow {
  0%   { filter: brightness(1); }
  100% { filter: brightness(1.3); }
}
.header p {
  color: var(--text-secondary);
  margin-top: 0.4rem;
  font-size: 0.95rem;
}

/* ===== Game Container ===== */
.game-container {
  width: 100%;
  max-width: 480px;
  padding: 0 1rem 2rem;
}

/* ===== Glass Card ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  transition: background 0.3s;
}

/* ===== Status Bar ===== */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.status-bar .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}
.status-bar .value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.1rem;
}

/* ===== Digit Slots ===== */
.slots-wrapper {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 1.4rem 0;
}
.slot {
  width: 72px;
  height: 88px;
  border-radius: 16px;
  border: 2.5px solid var(--slot-default);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(.4,0,.2,1);
  position: relative;
  background: transparent;
  user-select: none;
}
.slot:hover {
  border-color: rgba(0, 172, 193, 0.5);
  background: rgba(0, 172, 193, 0.06);
}
.slot.selected {
  border-color: var(--slot-selected);
  background: var(--digit-active);
  box-shadow: 0 0 20px var(--accent-glow), inset 0 0 20px rgba(0, 172, 193, 0.08);
  transform: translateY(-3px);
}
.slot.filled {
  background: var(--digit-filled);
  color: var(--text-primary);
}
.slot.selected.filled {
  background: var(--digit-active);
}

/* Cursor blink for selected empty slot */
.slot.selected:not(.filled)::after {
  content: '|';
  font-size: 2rem;
  color: var(--accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* ===== Number Pad ===== */
.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 1rem;
}
.num-btn {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 1.5px solid var(--glass-border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(.4,0,.2,1);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.num-btn:hover {
  background: var(--bg-card-hover);
  border-color: rgba(0, 172, 193, 0.4);
  transform: scale(1.06);
}
.num-btn:active {
  transform: scale(0.95);
  background: var(--digit-active);
}
.num-btn.used {
  opacity: 0.25;
  pointer-events: none;
}

/* ===== Action Buttons ===== */
.action-row {
  display: flex;
  gap: 10px;
}
.btn {
  flex: 1;
  padding: 14px 0;
  border-radius: 14px;
  border: none;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(.4,0,.2,1);
  user-select: none;
}
.btn-submit {
  background: linear-gradient(135deg, #00acc1, #26c6da);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-submit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--accent-glow);
}
.btn-submit:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.btn-clear {
  background: rgba(0,0,0,0.04);
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}
.btn-clear:hover {
  background: rgba(0,0,0,0.08);
  color: var(--text-primary);
}

/* ===== History Table ===== */
.history-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 0.7rem;
}
.history-list {
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,172,193,0.3) transparent;
}
.history-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 6px;
  background: rgba(255,255,255,0.4);
  border: 1px solid rgba(255,255,255,0.6);
  animation: slideIn 0.35s cubic-bezier(.4,0,.2,1);
  transition: background 0.2s;
}
.history-item:hover {
  background: rgba(255,255,255,0.7);
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.history-num {
  width: 28px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.history-guess {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.15em;
}
.history-result {
  display: flex;
  gap: 12px;
}
.badge {
  padding: 3px 10px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
}
.badge-hit {
  background: rgba(255, 107, 157, 0.15);
  color: var(--hit-color);
  border: 1px solid rgba(255, 107, 157, 0.25);
}
.badge-blow {
  background: rgba(81, 207, 102, 0.12);
  color: var(--blow-color);
  border: 1px solid rgba(81, 207, 102, 0.2);
}

/* ===== Victory Overlay ===== */
.victory-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(224, 247, 250, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s;
}
.victory-overlay.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.victory-card {
  text-align: center;
  padding: 3rem 2.5rem;
  border-radius: 28px;
  background: var(--success-bg);
  border: 1.5px solid var(--success-border);
  max-width: 380px;
  animation: popIn 0.5s cubic-bezier(.4,0,.2,1);
}
@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.victory-emoji { font-size: 4rem; margin-bottom: 0.8rem; }
.victory-card h2 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
  background: linear-gradient(135deg, #51cf66, #6c63ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.victory-stats {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 1.5rem;
  line-height: 1.7;
}
.victory-stats strong {
  color: var(--text-primary);
  font-weight: 700;
}
.btn-new-game {
  padding: 14px 36px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #51cf66, #40c057);
  color: #0a0e1a;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.25s;
}
.btn-new-game:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(81, 207, 102, 0.3);
}

/* ===== Confetti ===== */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1001;
  overflow: hidden;
}
.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  top: -20px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to {
    top: 110vh;
    transform: rotate(720deg);
  }
}

/* ===== Message Flash ===== */
.message {
  text-align: center;
  padding: 10px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: none;
  animation: slideIn 0.3s;
}
.message.error {
  display: block;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.25);
  color: #ff6b6b;
}

/* ===== Lives warning ===== */
.status-bar .value.low {
  color: var(--hit-color);
  animation: livesPulse 1s ease-in-out infinite;
}
@keyframes livesPulse {
  50% { opacity: 0.5; }
}

/* ===== Items ===== */
.items-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 0.7rem;
}
.item-row {
  display: flex;
  gap: 10px;
}
.btn-item {
  flex: 1;
  padding: 12px 0;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(.4,0,.2,1);
  user-select: none;
}
.btn-item:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: rgba(0, 172, 193, 0.4);
  transform: translateY(-2px);
}
.btn-item:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.item-hint {
  display: none;
  margin-top: 0.8rem;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  background: rgba(0, 172, 193, 0.12);
  border: 1px solid rgba(0, 172, 193, 0.25);
  color: var(--accent);
  animation: slideIn 0.3s;
}
.item-hint.show { display: block; }
.item-hint.error {
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.25);
  color: #ff6b6b;
}

/* ===== Game Over Overlay ===== */
.gameover-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s;
}
.gameover-overlay.show { display: flex; }
.gameover-card {
  text-align: center;
  padding: 3rem 2.5rem;
  border-radius: 28px;
  background: rgba(255, 107, 107, 0.15);
  border: 1.5px solid rgba(255, 107, 107, 0.4);
  max-width: 380px;
  animation: popIn 0.5s cubic-bezier(.4,0,.2,1);
}
.gameover-emoji { font-size: 4rem; margin-bottom: 0.8rem; }
.gameover-card h2 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
  color: var(--hit-color);
}
.gameover-stats {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 1.5rem;
  line-height: 1.7;
}
.gameover-stats strong { color: var(--text-primary); font-weight: 700; }

/* ===== Mode Menu ===== */
.mode-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.mode-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0, 172, 193, 0.15);
}
.mode-emoji { font-size: 2.6rem; line-height: 1; }
.mode-body { flex: 1; }
.mode-title { font-size: 1.25rem; font-weight: 800; }
.mode-desc { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.2rem; }
.mode-arrow { font-size: 1.6rem; color: var(--accent); font-weight: 800; }

/* ===== Back link ===== */
.back-link { margin-top: 0.5rem; }
.back-link a {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-decoration: none;
}
.back-link a:hover { color: var(--accent); }

/* ===== VS Setup ===== */
.setup-note {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.secret-input {
  width: 100%;
  padding: 18px;
  border-radius: 16px;
  border: 2.5px solid var(--slot-default);
  background: rgba(255, 255, 255, 0.5);
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.4em;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.secret-input:focus {
  border-color: var(--slot-selected);
  box-shadow: 0 0 20px var(--accent-glow);
}

/* ===== VS Handoff ===== */
.handoff-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0.6rem 0 0.3rem;
}
.handoff-detail { color: var(--text-secondary); font-size: 0.95rem; }

/* ===== VS Result ===== */
.vs-result-grid {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}
.result-card { flex: 1; text-align: center; margin-bottom: 0; }
.result-card.winner {
  border-color: var(--success-border);
  background: var(--success-bg);
  box-shadow: 0 0 24px rgba(81, 207, 102, 0.25);
}
.result-player { font-size: 1.1rem; font-weight: 800; margin-bottom: 0.4rem; }
.result-status { font-size: 0.95rem; margin-bottom: 0.8rem; }
.result-stats { display: flex; flex-direction: column; gap: 0.4rem; }
.result-stats > div {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}
.result-stats span { color: var(--text-secondary); }
.result-stats strong { font-family: var(--font-mono); }
.result-answer {
  margin-top: 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--hit-color);
}

/* ===== VS: lobby ===== */
.lobby-label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* ===== VS: turn banner ===== */
.vs-banner {
  text-align: center;
  font-weight: 800;
  font-size: 1.05rem;
  padding: 0.4rem 0;
}
.vs-banner.your-turn { color: var(--accent); }
.vs-banner.wait-turn,
.vs-banner.waiting { color: var(--text-secondary); }

/* ===== VS: boards ===== */
.vs-boards {
  display: flex;
  gap: 0.8rem;
}
.vs-board {
  flex: 1;
  min-width: 0;
  border-radius: 14px;
  padding: 0.7rem;
  background: rgba(255, 255, 255, 0.4);
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  transition: all 0.25s;
}
.vs-board.active {
  border-color: var(--slot-selected);
  box-shadow: 0 0 16px var(--accent-glow);
}
.vs-board.solved {
  border-color: var(--success-border);
  background: var(--success-bg);
}
.vs-name {
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.turn-dot {
  color: var(--accent);
  font-size: 0.7rem;
  animation: livesPulse 1s ease-in-out infinite;
}
.vs-history {
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.vs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 6px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: rgba(255, 255, 255, 0.5);
  animation: slideIn 0.3s;
}
.vs-row .history-guess { font-size: 1rem; letter-spacing: 0.1em; }
.vs-row .badge { padding: 2px 6px; font-size: 0.75rem; }
.vs-row .history-result { gap: 5px; }
.vs-empty {
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 6px;
  text-align: center;
}

/* 相手の番のとき入力欄をロック */
#input-card.locked { opacity: 0.5; pointer-events: none; }

/* 敗北時の結果カード */
.victory-card.lose {
  background: rgba(255, 107, 107, 0.15);
  border-color: rgba(255, 107, 107, 0.4);
}
.victory-card.lose h2 {
  background: none;
  -webkit-text-fill-color: initial;
  color: var(--hit-color);
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
  .slot { width: 60px; height: 74px; font-size: 1.8rem; }
  .num-btn { font-size: 1.2rem; }
  .header h1 { font-size: 1.8rem; }
  .btn-item { font-size: 0.85rem; }
}
