/* ===== JAセレ打川崎！ - Style ===== */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700;900&family=M+PLUS+Rounded+1c:wght@400;700;900&display=swap');

:root {
  --green: #2d7a3a;
  --green-light: #4caf50;
  --green-pale: #e8f5e9;
  --orange: #e65100;
  --orange-light: #ff9800;
  --brown: #5d4037;
  --yellow: #ffd600;
  --red: #c62828;
  --bg: #f1f8e9;
  --card-bg: #ffffff;
  --text: #1b2421;
  --text-muted: #555;
  --shadow: 0 4px 20px rgba(0,0,0,0.12);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'M PLUS Rounded 1c', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== BACKGROUND ===== */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at top left, #c8e6c9 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, #fff9c4 0%, transparent 50%);
  z-index: 0;
  pointer-events: none;
}

/* ===== SCREEN MANAGEMENT ===== */
.screen {
  display: none;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ===== TITLE SCREEN ===== */
#screen-title {
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  gap: 0;
}

.title-logo {
  margin-bottom: 8px;
}
.title-logo .game-icon {
  font-size: 4rem;
  display: block;
  margin-bottom: 8px;
  animation: bounce 2s infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.title-logo h1 {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 900;
  color: var(--green);
  text-shadow: 2px 2px 0 #a5d6a7, 4px 4px 0 rgba(0,0,0,0.1);
  line-height: 1.1;
}
.title-logo h1 span {
  color: var(--orange);
}
.catchcopy {
  font-size: clamp(0.75rem, 2.5vw, 0.95rem);
  color: var(--text-muted);
  margin-top: 10px;
  margin-bottom: 30px;
  line-height: 1.6;
}

.game-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px 36px;
  box-shadow: var(--shadow);
  width: min(500px, 92vw);
  margin-bottom: 20px;
}
.start-desc {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 10px;
}

.btn-start {
  width: 100%;
  padding: 16px;
  font-size: 1.3rem;
  font-weight: 900;
  font-family: inherit;
  background: linear-gradient(135deg, var(--green), var(--green-light));
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 0.05em;
  box-shadow: 0 4px 14px rgba(45,122,58,0.35);
  transition: all 0.15s;
}
.btn-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(45,122,58,0.45);
}
.btn-start:active { transform: translateY(0); }

.mode-btns { display: flex; gap: 10px; width: 100%; }
.mode-btns .btn-start { font-size: 1.05rem; padding: 14px 8px; }
.btn-start.btn-sp {
  background: linear-gradient(135deg, #1565c0, #1976d2);
  box-shadow: 0 4px 14px rgba(21,101,192,0.35);
}
.btn-start.btn-sp:hover { box-shadow: 0 6px 20px rgba(21,101,192,0.45); }

/* ===== VIRTUAL KEYBOARD ===== */
#virtual-kb {
  display: none;
  width: min(600px, 96vw);
  padding: 10px 6px 14px;
  background: #263238;
  border-radius: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}
.vkb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 5px;
}
.vkb-key {
  width: clamp(28px, 8.5vw, 44px);
  height: 46px;
  background: #546e7a;
  color: #eceff1;
  border: none;
  border-radius: 7px;
  font-size: clamp(0.8rem, 2.5vw, 1rem);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.08s, transform 0.05s;
  box-shadow: 0 3px 0 #1c313a;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.vkb-key:active, .vkb-key.tapped {
  background: #78909c;
  transform: translateY(2px);
  box-shadow: 0 1px 0 #1c313a;
}
.vkb-key.vkb-hint {
  background: var(--orange);
  color: #fff;
  box-shadow: 0 3px 0 #bf360c;
}

.btn-home {
  display: block;
  text-align: center;
  margin: 12px auto 0;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--green);
  background: var(--green-pale);
  border: 2px solid var(--green-light);
  border-radius: 999px;
  text-decoration: none;
  width: fit-content;
  transition: all 0.15s;
}
.btn-home:hover {
  background: var(--green-light);
  color: #fff;
}

.rules-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 28px;
  box-shadow: var(--shadow);
  width: min(500px, 92vw);
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.8;
}
.rules-card h3 { color: var(--green); margin-bottom: 10px; font-size: 0.9rem; }
.rules-card ul { padding-left: 18px; }
.rules-card li { margin-bottom: 4px; }

/* ===== GAME SCREEN ===== */
#screen-game {
  padding: 0;
  justify-content: flex-start;
}

#game-area {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 40px;
}

/* Countdown overlay */
#countdown-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  border-radius: var(--radius);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#countdown-overlay.active {
  display: flex;
}
#countdown-number {
  font-size: 9rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0,0,0,0.5);
  animation: countPop 0.6s ease-out;
}
@keyframes countPop {
  0%   { transform: scale(1.8); opacity: 0; }
  40%  { transform: scale(1.0); opacity: 1; }
  100% { transform: scale(1.0); opacity: 1; }
}

/* Danger pulse */
#game-area.danger-pulse {
  animation: dangerPulse 0.5s infinite;
}
@keyframes dangerPulse {
  0%, 100% { background: transparent; }
  50% { background: rgba(198, 40, 40, 0.06); }
}

/* HUD */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(600px, 96vw);
  margin-bottom: 20px;
  gap: 16px;
}

.timer-wrap {
  position: relative;
  width: 90px;
  height: 90px;
  flex-shrink: 0;
}
.timer-wrap svg {
  width: 90px;
  height: 90px;
  transform: rotate(-90deg);
}
.timer-bg { stroke: #e0e0e0; fill: none; stroke-width: 8; }
.timer-ring {
  stroke: var(--green);
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 251 251;
  transition: stroke-dasharray 0.9s linear, stroke 0.3s;
}
#timer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  color: var(--green);
  transition: color 0.3s;
}
#timer.danger {
  color: var(--red);
  animation: timerPulse 0.4s infinite;
}
#timer.danger ~ svg .timer-ring { stroke: var(--red); }
@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.score-combo {
  flex: 1;
  text-align: right;
}
.score-label { font-size: 0.8rem; color: var(--text-muted); }
#score {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--green);
  line-height: 1;
}
#combo-display {
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--orange);
  font-weight: 700;
  min-height: 20px;
  opacity: 0;
  transition: opacity 0.2s;
}
#combo-display.active { opacity: 1; }

/* Word area */
.word-area {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 32px 40px;
  box-shadow: var(--shadow);
  width: min(600px, 96vw);
  text-align: center;
  position: relative;
  margin-bottom: 20px;
}

#word-jp {
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 900;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: 0.05em;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s;
}
#word-jp.shake {
  animation: shake 0.25s;
  color: var(--red);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

#romaji-display {
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  font-family: 'Courier New', monospace;
  font-weight: 700;
  margin-top: 16px;
  letter-spacing: 0.08em;
  min-height: 40px;
}
.typed-chars { color: var(--green); }
.cursor-char {
  color: var(--orange);
  background: #fff9c4;
  border-bottom: 3px solid var(--orange);
  padding: 0 2px;
}
.rest-chars { color: #bbb; }

.input-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 12px;
}

/* Hidden input */
#hidden-input {
  position: fixed;
  top: -200px;
  left: 0;
  opacity: 0;
  width: 1px;
  height: 1px;
}

/* Combo popup */
.combo-popup {
  position: absolute;
  top: 10px;
  right: 10px;
  background: linear-gradient(135deg, var(--orange), var(--orange-light));
  color: #fff;
  font-weight: 900;
  font-size: 1rem;
  padding: 6px 14px;
  border-radius: 20px;
  box-shadow: 0 2px 10px rgba(230,81,0,0.4);
  animation: popupFloat 0.9s ease-out forwards;
  pointer-events: none;
}
@keyframes popupFloat {
  0%   { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

/* ===== RESULT SCREEN ===== */
#screen-result {
  padding: 30px 16px 60px;
  gap: 20px;
  align-items: center;
}

.result-header {
  text-align: center;
  width: min(600px, 96vw);
}
.result-header h2 {
  font-size: 1.5rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
#result-title-emoji { font-size: 3rem; display: block; margin-bottom: 4px; }
#result-title {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--green);
  display: block;
  margin-bottom: 8px;
}
#result-score {
  font-size: 4rem;
  font-weight: 900;
  color: var(--orange);
  display: block;
  line-height: 1;
}
.result-score-label { font-size: 1.2rem; color: var(--text-muted); }
#result-stats {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.trivia-card, .ranking-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px 28px;
  box-shadow: var(--shadow);
  width: min(600px, 96vw);
}
.trivia-card h3, .ranking-card h3 {
  color: var(--green);
  margin-bottom: 14px;
  font-size: 1rem;
  font-weight: 700;
}
#trivia-list {
  list-style: none;
  padding: 0;
}
#trivia-list li {
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.88rem;
  line-height: 1.7;
}
#trivia-list li:last-child { border-bottom: none; }

#ranking-form {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
#ranking-name {
  flex: 1;
  min-width: 160px;
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
}
#ranking-name:focus { border-color: var(--green-light); }
#btn-ranking-submit {
  padding: 10px 20px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
#btn-ranking-submit:hover { background: var(--green-light); transform: translateY(-1px); }

.rank-submitted { color: var(--green); font-weight: 700; }
.rank-error { color: var(--red); }

.ranking-ol {
  list-style: none;
  padding: 0;
}
.ranking-ol li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  margin-bottom: 6px;
  background: #fafafa;
  counter-increment: rank-counter;
  font-size: 0.9rem;
}
.ranking-ol li::before {
  content: counter(rank-counter);
  font-weight: 900;
  color: var(--text-muted);
  min-width: 22px;
  text-align: center;
}
.ranking-ol { counter-reset: rank-counter; }
.ranking-ol li.top1 { background: #fff9c4; }
.ranking-ol li.top1::before { color: #f9a825; font-size: 1.1rem; }
.ranking-ol li.top2 { background: #f5f5f5; }
.ranking-ol li.top2::before { color: #757575; font-size: 1rem; }
.ranking-ol li.top3 { background: #fbe9e7; }
.ranking-ol li.top3::before { color: var(--orange); }
.rank-name { flex: 1; font-weight: 700; }
.rank-title { font-size: 0.78rem; color: var(--text-muted); }
.rank-score { font-weight: 900; color: var(--green); }

#btn-play-again {
  padding: 14px 40px;
  font-size: 1.1rem;
  font-weight: 900;
  font-family: inherit;
  background: linear-gradient(135deg, var(--orange), var(--orange-light));
  color: #fff;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(230,81,0,0.35);
  transition: all 0.15s;
}
#btn-play-again:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(230,81,0,0.45);
}

/* ===== TOP PAGE RANKING ===== */
.top-ranking-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 28px;
  box-shadow: var(--shadow);
  width: min(500px, 92vw);
  margin-bottom: 20px;
}
.top-ranking-card h3 {
  color: var(--green);
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 700;
}
.rank-loading { font-size: 0.85rem; color: var(--text-muted); text-align: center; padding: 10px 0; }
#top-ranking-list .ranking-ol { margin: 0; }
#top-ranking-list .ranking-ol li { font-size: 0.85rem; padding: 6px 10px; }
#top-ranking-list .ranking-ol li .rank-title { font-size: 0.72rem; }
.rank-empty { font-size: 0.85rem; color: var(--text-muted); text-align: center; padding: 10px 0; }

/* ===== TITLES TABLE ===== */
.titles-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 28px;
  box-shadow: var(--shadow);
  width: min(500px, 92vw);
  margin-bottom: 40px;
}
.titles-card h3 {
  color: var(--green);
  margin-bottom: 14px;
  font-size: 0.9rem;
  font-weight: 700;
}
.titles-table {
  width: 100%;
  border-collapse: collapse;
}
.titles-table tr {
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.1s;
}
.titles-table tr:last-child { border-bottom: none; }
.titles-table tr:hover { background: var(--green-pale); }
.title-emoji { width: 36px; font-size: 1.3rem; text-align: center; padding: 7px 4px; }
.title-score { width: 80px; font-size: 0.82rem; color: var(--text-muted); padding: 7px 8px; font-variant-numeric: tabular-nums; }
.title-name  { font-size: 0.9rem; font-weight: 700; padding: 7px 4px; }
/* 最高位をゴールドで強調 */
.titles-table tr:last-child .title-name { color: #e65100; }
.titles-table tr:last-child .title-emoji { filter: drop-shadow(0 0 4px gold); }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .game-card { padding: 20px; }
  .word-area { padding: 24px 20px; }
  .diff-buttons { gap: 6px; }
  .diff-btn { padding: 10px 6px; font-size: 0.82rem; }
}
