@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&family=Outfit:wght@400;600;800&family=Roboto+Mono:wght@400;500;700&display=swap');

:root {
  /* Colors */
  --color-bg-main: #0f172a;
  --color-bg-gradient: radial-gradient(circle at top right, #1e293b, #0f172a);

  --color-glass-surface: rgba(30, 41, 59, 0.7);
  --color-glass-border: rgba(255, 255, 255, 0.1);
  --color-glass-highlight: rgba(255, 255, 255, 0.05);

  --color-text-primary: #f8fafc;
  --color-text-secondary: #94a3b8;
  --color-text-muted: #475569;

  --color-accent-primary: #3b82f6;
  /* Blue */
  --color-accent-cyan: #06b6d4;
  /* Cyan */
  --color-accent-pink: #ec4899;
  /* Pink/Error */
  --color-accent-success: #10b981;
  /* Green */

  --gradient-primary: linear-gradient(135deg, #3b82f6, #06b6d4);
  --gradient-error: linear-gradient(135deg, #ef4444, #ec4899);

  /* Typography */
  --font-main: 'Outfit', 'Noto Sans JP', sans-serif;
  --font-mono: 'Roboto Mono', monospace;

  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 0.75rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2.5rem;
  --spacing-xl: 4rem;

  /* UI */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;

  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);
}

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

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

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

/* --- Layout --- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
  width: 100%;
}

main {
  flex: 1;
  display: flex;
  flex-direction: row;
  justify-content: center;
  position: relative;
  z-index: 10;
  gap: 1rem;
}

.main-content {
  flex: 1;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
}

/* ==========================================
   Sidebar Ads
   ========================================== */
.ad-sidebar {
  width: 160px;
  min-width: 160px;
  position: sticky;
  top: 80px;
  height: fit-content;
  align-self: flex-start;
}

.ad-sidebar-left {
  margin-left: 1rem;
}

.ad-sidebar-right {
  margin-right: 1rem;
}

/* 広告が読み込まれるまでのプレースホルダー */
.ad-sidebar ins.adsbygoogle {
  min-height: 600px;
  background: var(--color-glass-surface);
  border-radius: var(--radius-sm);
}

/* タブレット以下では非表示 */
@media (max-width: 1200px) {
  .ad-sidebar {
    display: none;
  }

  main {
    flex-direction: column;
  }
}

/* --- Glassmorphism Components --- */
.glass-card {
  background: var(--color-glass-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.btn {
  font-family: var(--font-main);
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px rgba(59, 130, 246, 0.5);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--color-glass-border);
  color: var(--color-text-primary);
}

.btn-secondary:hover {
  background: var(--color-glass-highlight);
  border-color: var(--color-text-secondary);
}

.text-gradient {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* --- Header --- */
.header {
  padding: var(--spacing-md) 0;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 50;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 1.5rem;
  color: white;
  text-decoration: none;
  letter-spacing: -0.02em;
  cursor: pointer;
}

.btn-icon {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: color 0.2s;
  padding: 0.5rem;
}

.btn-icon:hover {
  color: white;
  transform: rotate(15deg);
}

/* --- Sections --- */
.hidden {
  display: none !important;
}

/* --- Home Screen --- */
#home-screen {
  padding: 6rem 0 4rem;
  align-self: flex-start;
  width: 100%;
}

.hero-title {
  font-size: 4rem;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  margin-bottom: 1rem;
}

.hero-subtitle {
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 1.25rem;
  margin-bottom: 4rem;
}

.section-title {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 2rem;
}

/* Level Grid */
/* Level Categories */
.level-category {
  margin-bottom: 3rem;
}

.category-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-left: 0.5rem;
  border-left: 4px solid var(--color-accent-primary);
  color: var(--color-text-primary);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.level-card {
  padding: 1rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.level-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  background: var(--gradient-primary) border-box;
  -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.3s;
}

.level-card:hover {
  transform: translateY(-3px);
  background: rgba(30, 41, 59, 0.9);
}

.level-card.selected::after {
  opacity: 1;
}

.level-card.selected {
  background: rgba(59, 130, 246, 0.1);
}

.level-name {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.level-desc {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-meta {
  display: flex;
  gap: 0.5rem;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
}

/* Mode Selector */
.mode-selector {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 3rem;
}

.mode-btn {
  padding: 1rem 2rem;
  background: transparent;
  border: 1px solid var(--color-glass-border);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.mode-btn.active {
  background: var(--color-accent-primary);
  color: white;
  border-color: var(--color-accent-primary);
  box-shadow: var(--shadow-glow);
}

.start-btn-container {
  display: flex;
  justify-content: center;
}

/* --- Game Screen --- */
#game-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.game-container {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.game-hud {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3rem;
  font-family: var(--font-mono);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.hud-value {
  font-size: 2rem;
  font-weight: 700;
}

.hud-item-score {
  flex: 1;
  text-align: center;
}

.hud-score-value {
  font-size: 3rem;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Progress Bar */
.progress-container {
  width: 100%;
  height: 6px;
  background: var(--color-glass-border);
  border-radius: 3px;
  margin-bottom: 3rem;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--gradient-primary);
  width: 100%;
  /* JS updates this */
  transition: width 0.1s linear;
}

/* Typing Area */
.typing-area {
  text-align: center;
  padding: 4rem 2rem;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.word-display {
  margin-bottom: 3rem;
  position: relative;
}

.current-word {
  font-family: var(--font-mono);
  font-size: 4.5rem;
  font-weight: 500;
  margin-bottom: 1rem;
  line-height: 1.2;
  word-break: normal;
  overflow-wrap: break-word;
}

.char-correct {
  color: var(--color-accent-success);
  /* Green for correct */
  text-shadow: 0 0 5px rgba(16, 185, 129, 0.3);
}

.char-target {
  color: var(--color-text-primary);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
  position: relative;
}

.char-target.char-error {
  color: var(--color-accent-pink);
  text-shadow: 0 0 10px var(--color-accent-pink);
  animation: flash-error 0.4s ease;
}

.char-target::after {
  /* カーソル */
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--color-accent-cyan);
  animation: blink 1s infinite;
}

.char-future {
  color: var(--color-text-secondary);
  opacity: 0.5;
}

@keyframes flash-error {

  0%,
  100% {
    color: var(--color-accent-pink);
  }

  50% {
    opacity: 0.5;
  }
}

.phonetic {
  font-family: var(--font-mono);
  color: var(--color-accent-cyan);
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.meaning {
  font-size: 1.5rem;
  color: var(--color-text-primary);
}

.combo-display {
  font-weight: 800;
  color: var(--color-accent-primary);
  text-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
  height: 5rem;
  line-height: 5rem;
  font-size: 2rem;
}

.combo-display.hidden {
  display: block !important;
  visibility: hidden;
}

/* --- Result Screen --- */
#result-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.result-container {
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
  animation: slideUp 0.5s ease;
}

.result-title {
  font-size: 3rem;
  margin-bottom: 2rem;
}

.result-score-container {
  text-align: center;
  margin-bottom: 3rem;
}

.result-score-label {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  letter-spacing: 0.2em;
  margin-bottom: 0.5rem;
}

.result-score {
  font-size: 9rem;
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  filter: drop-shadow(0 0 30px rgba(59, 130, 246, 0.5));
}

.result-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-box {
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
}

.stat-box-label {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
}

.stat-box-value {
  font-size: 2rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* 苦手単語・キーセクション */
.missed-section {
  margin-bottom: 2rem;
  text-align: left;
}

.missed-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-accent-pink);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-glass-border);
}

.missed-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
}

.missed-word-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(236, 72, 153, 0.1);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-accent-pink);
}

.missed-word-text {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-text-primary);
}

.missed-word-meaning {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin-left: 1rem;
}

.missed-word-count {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--color-accent-pink);
  font-weight: 600;
}

.missed-keys-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  max-height: 150px;
  overflow-y: auto;
}

.missed-key-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(236, 72, 153, 0.1);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(236, 72, 153, 0.3);
}

.missed-key-expected {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-accent-pink);
  min-width: 1.5rem;
  text-align: center;
}

.missed-key-arrow {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.missed-key-actual {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--color-text-secondary);
}

.missed-key-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-accent-pink);
  margin-left: 0.25rem;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
}

/* --- Settings Panel --- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.settings-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 400px;
  height: 100vh;
  background: #1e293b;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
  padding: 2rem;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  overflow-y: auto;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.option-item {
  padding: 1rem;
  border: 1px solid var(--color-glass-border);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.option-item:hover {
  background: var(--color-glass-highlight);
}

.option-item.selected {
  border-color: var(--color-accent-primary);
  background: rgba(59, 130, 246, 0.1);
}

/* --- Animations --- */
@keyframes pop-char {
  0% {
    transform: scale(1);
    color: var(--color-text-primary);
  }

  50% {
    transform: scale(1.5);
    color: var(--color-accent-cyan);
    text-shadow: 0 0 10px var(--color-accent-cyan);
  }

  100% {
    transform: scale(1);
    color: var(--color-text-muted);
  }
}

.anim-pop {
  animation: pop-char 0.3s ease-out forwards;
}

@keyframes shake-screen {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-10px);
  }

  40% {
    transform: translateX(10px);
  }

  60% {
    transform: translateX(-5px);
  }

  80% {
    transform: translateX(5px);
  }
}

.anim-shake {
  animation: shake-screen 0.4s ease-in-out;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Additional Utility Classes (replace inline styles) --- */

/* Level container */
.level-container {
  max-width: 800px;
}

/* Settings group title */
.settings-group-title {
  margin-bottom: 1rem;
  color: var(--color-accent-cyan);
}

/* Option description */
.option-desc {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

/* Start button */
.btn-start {
  padding: 1rem 3rem;
  font-size: 1.25rem;
}

/* Game container padding */
.game-container-padding {
  padding: 2rem;
}

/* Typing hint */
.typing-hint {
  margin-top: 2rem;
  color: var(--color-text-muted);
}

/* Result card padding */
.result-card-padding {
  padding: 3rem;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
  .hero-title {
    font-size: 2.5rem;
  }

  .current-word {
    font-size: 2.5rem;
  }

  .result-score {
    font-size: 5rem;
  }

  .result-stats-grid {
    grid-template-columns: 1fr;
  }

  .hud-score-value {
    font-size: 2rem;
  }

  .game-hud {
    margin-bottom: 1.5rem;
  }

  .hud-value {
    font-size: 1.5rem;
  }

  .btn-start {
    padding: 0.75rem 2rem;
    font-size: 1rem;
  }

  .game-container-padding {
    padding: 1rem;
  }

  .result-card-padding {
    padding: 1.5rem;
  }
}

/* ==========================================
   Footer
   ========================================== */
.footer {
  margin-top: auto;
  padding: 1.5rem 0;
  border-top: 1px solid var(--color-glass-border);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

.footer-nav a {
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-nav a:hover {
  color: var(--color-text-primary);
}

@media (max-width: 480px) {
  .footer-content {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }
}