:root {
  --navy: #10213c;
  --blue: #2979ff;
  --cyan: #22c1dc;
  --red: #ef476f;
  --yellow: #ffca3a;
  --green: #2cc970;
  --paper: #ffffff;
  --bg: #edf4ff;
  --muted: #61718a;
  --line: #d9e4f4;
  --shadow: 0 18px 50px rgba(16, 33, 60, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--navy);
  background:
    radial-gradient(circle at 12% 8%, rgba(34, 193, 220, 0.2), transparent 28%),
    radial-gradient(circle at 88% 16%, rgba(41, 121, 255, 0.18), transparent 30%),
    linear-gradient(160deg, #f7fbff 0%, var(--bg) 100%);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
}

button, input, select, textarea { font: inherit; }
button, .back-link { -webkit-tap-highlight-color: transparent; }

button {
  min-height: 46px;
  border: 1px solid #c6d5ea;
  border-radius: 12px;
  padding: 10px 16px;
  color: var(--navy);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .back-link:focus-visible {
  outline: 3px solid rgba(41, 121, 255, 0.35);
  outline-offset: 2px;
}

.battle-app {
  width: min(1020px, calc(100% - 28px));
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom));
}

.battle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 4px 22px;
}

.battle-header h1 { margin: 2px 0 4px; font-size: clamp(1.6rem, 4vw, 2.5rem); }
.eyebrow, .step-label { margin: 0; color: var(--blue); font-size: 0.76rem; font-weight: 900; letter-spacing: 0.16em; }
.subtitle, .support-text { color: var(--muted); }
.subtitle { margin: 0; }

.back-link {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 1px solid #c6d5ea;
  border-radius: 12px;
  color: var(--navy);
  background: rgba(255,255,255,0.82);
  text-decoration: none;
  font-weight: 800;
}

.global-message { min-height: 24px; margin: 0 4px 8px; color: var(--red); font-weight: 700; }

.battle-card {
  padding: clamp(18px, 4vw, 32px);
  border: 1px solid rgba(198, 213, 234, 0.85);
  border-radius: 24px;
  background: rgba(255,255,255,0.94);
  box-shadow: var(--shadow);
}

.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.section-heading h2, .battle-card h2 { margin: 5px 0 0; }
.rule-chip { padding: 8px 12px; border-radius: 999px; background: #e8f2ff; color: #145ecf; font-weight: 800; font-size: 0.86rem; }

.setup-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; margin-top: 24px; }
.field { display: grid; gap: 7px; color: var(--muted); font-size: 0.9rem; font-weight: 800; }
.field select, .field input, .join-row input {
  width: 100%;
  min-height: 48px;
  border: 1px solid #bfcfe4;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--navy);
  background: #fff;
}
.setup-grid-three { grid-template-columns: 1.25fr 0.75fr 1fr; }
.range-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }

.match-choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; margin-top: 24px; }
.choice-card { position: relative; overflow: hidden; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: #f9fbff; }
.choice-card h3 { margin: 6px 0; }
.choice-card p { margin: 0 0 18px; color: var(--muted); }
.choice-icon { display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 8px; border-radius: 10px; background: #e8f2ff; color: var(--blue); font-weight: 900; }
.accent-card { background: linear-gradient(145deg, #fff8fa, #fff); border-color: #f4cad5; }
.accent-card .choice-icon { background: #ffe8ee; color: var(--red); }
.primary-btn { color: #fff; border-color: var(--blue); background: linear-gradient(135deg, var(--blue), #1764d6); }
.danger-btn { color: #fff; border-color: var(--red); background: linear-gradient(135deg, var(--red), #d72f59); }
.choice-card > button { width: 100%; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.join-row input { text-transform: uppercase; letter-spacing: 0.12em; font-weight: 900; }

.rules-details { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); }
.rules-details summary { cursor: pointer; color: var(--navy); font-weight: 800; }
.rules-details li + li { margin-top: 7px; }

#lobby-view { text-align: center; }
.waiting-orbit { width: 68px; height: 68px; margin: 4px auto 18px; padding: 7px; border: 3px solid #dbe8f9; border-top-color: var(--blue); border-radius: 50%; animation: spin 1.1s linear infinite; }
.waiting-orbit span { display: block; width: 100%; height: 100%; border-radius: 50%; background: linear-gradient(145deg, var(--cyan), var(--blue)); }
@keyframes spin { to { transform: rotate(360deg); } }
.room-code-panel { width: min(360px,100%); margin: 20px auto; padding: 16px; border-radius: 16px; background: #eef5ff; }
.room-code-panel span { display: block; color: var(--muted); font-size: 0.84rem; }
.room-code-panel strong { display: block; margin: 6px 0 12px; font-size: 2rem; letter-spacing: 0.18em; }
.config-summary { margin: 16px auto; color: var(--muted); }
.quiet-btn { margin-top: 8px; color: var(--muted); background: transparent; }

.battle-hud { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.player-panel { padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,0.9); box-shadow: 0 8px 24px rgba(16,33,60,0.08); }
.opponent-panel { border-top: 4px solid var(--red); }
.self-panel { border-top: 4px solid var(--blue); }
.player-title, .player-stats { display: flex; justify-content: space-between; gap: 10px; }
.player-title strong { font-size: 0.85rem; }
.player-stats { margin-top: 8px; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.gauge-track { height: 10px; margin-top: 10px; overflow: hidden; border-radius: 99px; background: #e7edf6; }
.gauge-fill { width: 0; height: 100%; transition: width 0.25s ease; }
.opponent-gauge { background: linear-gradient(90deg, #ff8aa6, var(--red)); }
.self-gauge { background: linear-gradient(90deg, var(--cyan), var(--blue)); }
.match-center { display: grid; min-width: 118px; text-align: center; color: var(--muted); font-size: 0.75rem; }
.match-center strong { margin: 3px 0; color: var(--navy); font-size: 1rem; }

.turn-stage { margin-top: 16px; padding: clamp(18px,4vw,34px); border-radius: 24px; background: rgba(255,255,255,0.96); box-shadow: var(--shadow); text-align: center; }
.timer-wrap { position: relative; width: 128px; height: 128px; margin: 0 auto; }
.timer-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-ring circle { fill: none; stroke-width: 8; }
.timer-ring-bg { stroke: #e6edf7; }
.timer-ring-progress { stroke: var(--blue); stroke-linecap: round; stroke-dasharray: 326.73; stroke-dashoffset: 0; transition: stroke 0.2s; }
.timer-value { position: absolute; inset: 0; display: grid; place-content: center; }
.timer-value strong { font-size: 1.8rem; line-height: 1; }
.timer-value span { margin-top: 4px; color: var(--muted); font-size: 0.66rem; font-weight: 900; letter-spacing: 0.12em; }
.turn-label { color: var(--blue); font-weight: 900; }
.question-area { margin: 20px auto; }
.question-area span { color: var(--muted); font-size: 0.82rem; font-weight: 800; }
.question-area p { margin: 8px auto 0; max-width: 820px; font-size: clamp(1.25rem,4vw,2rem); font-weight: 900; line-height: 1.55; }
.opponent-turn-area { min-height: 118px; display: grid; place-content: center; color: var(--muted); font-weight: 800; }
.typing-dots { display: flex; justify-content: center; gap: 7px; }
.typing-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--red); animation: pulse 1.1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%,70%,100% { transform: translateY(0); opacity: 0.35; } 35% { transform: translateY(-7px); opacity: 1; } }
.answer-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; max-width: 820px; margin: 18px auto 0; }
.answer-form textarea {
  width: 100%;
  min-width: 0;
  min-height: 58px;
  max-height: 180px;
  resize: none;
  overflow-y: auto;
  border: 2px solid #b8cae4;
  border-radius: 14px;
  padding: 13px 14px;
  color: var(--navy);
  background: #fff;
  font-size: 1.08rem;
  line-height: 1.5;
}
.answer-feedback { min-height: 24px; max-width: 820px; margin: 8px auto; color: var(--red); font-weight: 800; }
.feedback-message { margin: 0 0 8px; }
.correction-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; text-align: left; }
.correction-item { display: grid; gap: 2px; padding: 9px 12px; border: 1px solid #f3c0cd; border-radius: 11px; background: #fff4f7; }
.correction-label { color: #a72d4b; font-size: 0.74rem; }
.correction-item strong { color: var(--navy); font-size: 0.92rem; overflow-wrap: anywhere; }
.answer-shake { animation: answer-shake 0.24s ease-out; }
@keyframes answer-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 55% { transform: translateX(6px); } 80% { transform: translateX(-3px); } }
.skill-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; max-width: 720px; margin: 18px auto 0; }
.skill-actions p { grid-column: 1/-1; margin: 0; color: var(--yellow); font-weight: 900; letter-spacing: 0.12em; }
.skill-actions button span { display: block; font-weight: 900; }
.attack-skill { color: #9c1f3c; border-color: #f4b4c4; background: #fff0f4; }
.extend-skill { color: #075ca6; border-color: #add8f3; background: #edf8ff; }
.event-message { min-height: 26px; margin: 12px 0 0; text-align: center; color: var(--navy); font-weight: 900; }

.result-card { text-align: center; }
.result-rally { display: flex; justify-content: center; align-items: baseline; gap: 8px; margin: 24px 0; }
.result-rally span { color: var(--muted); font-weight: 800; }
.result-rally strong { font-size: 3.4rem; color: var(--blue); }
.result-stats { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; margin: 20px auto; max-width: 620px; }
.result-stat { padding: 16px; border-radius: 14px; background: #f3f7fd; }
.result-stat strong { display: block; margin-top: 4px; font-size: 1.35rem; }
.result-card > button { min-width: 220px; margin-top: 10px; }
.result-review-section { max-width: 760px; margin: 26px auto 10px; padding-top: 22px; border-top: 1px solid var(--line); text-align: left; }
.result-review-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.result-review-heading h3 { margin: 4px 0 0; }
.result-review-heading .quiet-btn { margin: 0; }
.result-word-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; margin-top: 14px; }
.review-word-card { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #f8fbff; }
.review-word-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.review-word-top strong { color: var(--blue); font-size: 1.18rem; overflow-wrap: anywhere; }
.review-word-top span { flex: 0 0 auto; padding: 3px 8px; border-radius: 999px; color: #a72d4b; background: #ffe8ee; font-size: 0.75rem; font-weight: 900; }
.review-entered, .review-meta { margin: 7px 0 0; color: var(--muted); font-size: 0.84rem; overflow-wrap: anywhere; }
.review-word-card details { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
.review-word-card summary { cursor: pointer; color: var(--navy); font-size: 0.84rem; font-weight: 800; }
.review-word-card details p { margin: 7px 0 0; color: var(--muted); font-size: 0.84rem; line-height: 1.55; }
.review-word-card .review-correct-sentence { color: var(--navy); font-weight: 700; }
.result-no-mistakes { max-width: 620px; margin: 22px auto; padding: 16px; border-radius: 14px; color: #137143; background: #e9fbf1; font-weight: 900; }

.timer-danger .timer-ring-progress { stroke: var(--red); }
.player-panel.active-turn { box-shadow: 0 0 0 3px rgba(41,121,255,0.18), 0 10px 28px rgba(16,33,60,0.12); }
.hidden { display: none !important; }

@media (max-width: 700px) {
  .battle-app { width: min(100% - 18px, 1020px); }
  .battle-header { align-items: flex-start; }
  .back-link { padding: 9px 10px; font-size: 0.82rem; }
  .setup-grid, .setup-grid-three, .match-choice-grid { grid-template-columns: 1fr; }
  .battle-hud { grid-template-columns: 1fr 1fr; }
  .match-center { grid-column: 1/-1; grid-row: 1; grid-template-columns: repeat(3,1fr); }
  .opponent-panel { grid-column: 1; grid-row: 2; }
  .self-panel { grid-column: 2; grid-row: 2; }
  .player-title, .player-stats { display: grid; }
  .player-title strong, .player-stats { font-size: 0.7rem; }
  .turn-stage { margin-top: 10px; }
  .answer-form { grid-template-columns: 1fr; }
  .skill-actions { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: 1fr 1fr; }
  .result-word-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
