/* ===== CSS Variables ===== */
:root {
  --bg: #0a0a0f;
  --surface: #14141f;
  --border: #2a2a3a;
  --pink: #ff2d78;
  --cyan: #00e5ff;
  --gold: #ffd700;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --green: #00e676;
  --yellow: #ffeb3b;
  --red: #ff1744;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== Header ===== */
.header {
  width: 100%;
  padding: 20px 16px 14px;
  text-align: center;
  background: linear-gradient(135deg, #1a0a2e 0%, #0d0d1a 50%, #0a1a2e 100%);
  border-bottom: 2px solid var(--border);
}

.header-title {
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  font-weight: 900;
  background: linear-gradient(90deg, var(--pink), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.3;
}

.header-sub {
  display: block;
  font-size: 0.55em;
  letter-spacing: 0.15em;
  opacity: 0.8;
}

.header-subtitle {
  margin-top: 6px;
  font-size: clamp(0.8rem, 2.5vw, 1rem);
  color: var(--text-dim);
}

.subtitle-en {
  margin-left: 8px;
  opacity: 0.7;
}

/* ===== Game Container ===== */
.game-container {
  width: 100%;
  max-width: 600px;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===== Stats Bar ===== */
.stats-bar {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--gold);
}

/* ===== Game Area ===== */
.game-area {
  display: flex;
  gap: 16px;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

/* ===== Muscle Meter ===== */
.meter-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 60px;
}

.meter-label {
  font-size: 0.6rem;
  color: var(--text-dim);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.3;
}

.meter-container {
  position: relative;
  flex: 1;
  display: flex;
  align-items: stretch;
}

.meter-bar {
  width: 36px;
  height: 100%;
  min-height: 160px;
  background: #1a1a2a;
  border-radius: 18px;
  border: 2px solid var(--border);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: flex-end;
}

.meter-fill {
  width: 100%;
  height: 100%;
  border-radius: 16px;
  background: linear-gradient(to top, var(--green), var(--green));
  transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
              background 0.5s ease;
  position: relative;
}

.meter-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 4px;
  right: 4px;
  height: 40%;
  background: linear-gradient(to bottom, rgba(255,255,255,0.2), transparent);
  border-radius: 12px 12px 0 0;
}

.meter-fill.level-high {
  background: linear-gradient(to top, var(--green), #66ff99);
}

.meter-fill.level-mid {
  background: linear-gradient(to top, var(--yellow), #fff176);
}

.meter-fill.level-low {
  background: linear-gradient(to top, var(--red), #ff5252);
}

.meter-remaining {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dim);
}

.meter-icons {
  display: none;
}

/* ===== Word Section ===== */
.word-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.category-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid rgba(0, 229, 255, 0.2);
  border-radius: 20px;
  font-size: 0.8rem;
}

.category-label {
  color: var(--text-dim);
}

.category-value {
  color: var(--cyan);
  font-weight: 700;
}

/* Word Display */
.word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 10px 0;
  min-height: 70px;
  align-items: center;
}

.letter-slot {
  width: 32px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  position: relative;
}

.letter-slot::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 2px;
  right: 2px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  transition: background 0.3s;
}

.letter-slot.revealed {
  animation: revealLetter 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.letter-slot.revealed::after {
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.5);
}

@keyframes revealLetter {
  0% { transform: scale(0.5) rotateX(90deg); opacity: 0; }
  50% { transform: scale(1.2) rotateX(0deg); opacity: 1; }
  100% { transform: scale(1) rotateX(0deg); opacity: 1; }
}

.letter-slot.win-reveal {
  animation: winBounce 0.5s ease forwards;
}

@keyframes winBounce {
  0% { transform: scale(1); color: var(--text); }
  50% { transform: scale(1.3); color: var(--gold); }
  100% { transform: scale(1); color: var(--gold); }
}

/* Hint */
.hint-btn {
  padding: 6px 16px;
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.hint-btn:hover {
  background: rgba(255, 215, 0, 0.1);
}

.hint-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.hint-text {
  font-size: 0.8rem;
  color: var(--gold);
  text-align: center;
  min-height: 1.2em;
  font-style: italic;
}

/* ===== Keyboard ===== */
.keyboard {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  padding: 4px;
}

.key-btn {
  aspect-ratio: 1;
  max-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  font-weight: 700;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.key-btn:hover:not(:disabled) {
  background: #1e1e30;
  border-color: var(--cyan);
  transform: scale(1.05);
}

.key-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.key-btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.key-btn.correct {
  background: rgba(0, 229, 255, 0.15);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

.key-btn.wrong {
  background: rgba(255, 23, 68, 0.15);
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 0 10px rgba(255, 23, 68, 0.2);
}

/* ===== New Game Button ===== */
.new-game-btn {
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--pink), #cc1155);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.new-game-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 45, 120, 0.4);
}

/* ===== Overlays ===== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.overlay.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-content {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  max-width: 400px;
  width: 100%;
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.win-content {
  border-color: var(--gold);
  box-shadow: 0 0 40px rgba(255, 215, 0, 0.15);
}

.lose-content {
  border-color: var(--red);
  box-shadow: 0 0 40px rgba(255, 23, 68, 0.15);
}

.overlay-icon {
  font-size: 3.5rem;
  margin-bottom: 8px;
}

.overlay-title {
  font-size: 1.6rem;
  font-weight: 900;
  margin-bottom: 12px;
}

.win-content .overlay-title {
  background: linear-gradient(90deg, var(--gold), #ffee58);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.lose-content .overlay-title {
  color: var(--red);
}

.overlay-answer-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.overlay-word {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  margin-bottom: 8px;
  color: var(--cyan);
}

.overlay-msg {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.btn-share {
  padding: 10px 20px;
  background: #1da1f2;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-share:hover {
  background: #0d8ddb;
  transform: translateY(-1px);
}

.btn-play-again {
  padding: 10px 20px;
  background: linear-gradient(135deg, var(--pink), #cc1155);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-play-again:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(255, 45, 120, 0.4);
}

/* ===== Patreon CTA ===== */
.patreon-cta {
  text-align: center;
}

.patreon-link {
  display: inline-block;
  padding: 12px 24px;
  background: linear-gradient(135deg, #f96854, #e5503c);
  color: #fff;
  text-decoration: none;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  transition: all 0.2s;
}

.patreon-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(249, 104, 84, 0.4);
}

.patreon-emoji {
  font-style: normal;
}

/* ===== How to Play ===== */
.how-to-play {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.how-to-play summary {
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--cyan);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.how-to-play summary::before {
  content: '\25B6';
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.how-to-play[open] summary::before {
  transform: rotate(90deg);
}

.how-to-play-content {
  padding: 0 20px 20px;
}

.how-to-play-content ol {
  list-style: none;
  counter-reset: steps;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.how-to-play-content li {
  counter-increment: steps;
  position: relative;
  padding-left: 36px;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.how-to-play-content li::before {
  content: counter(steps);
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  background: var(--pink);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.how-to-play-content strong {
  color: var(--text);
}

/* ===== Footer ===== */
.footer {
  width: 100%;
  text-align: center;
  padding: 20px 16px;
  color: var(--text-dim);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.footer a {
  color: var(--pink);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .game-area {
    padding: 14px;
    gap: 12px;
  }

  .meter-section {
    min-width: 48px;
  }

  .meter-bar {
    width: 28px;
  }

  .letter-slot {
    width: 26px;
    height: 38px;
    font-size: 1.3rem;
  }

  .keyboard {
    gap: 4px;
  }

  .key-btn {
    font-size: 0.85rem;
    border-radius: 6px;
  }

  .stats-bar {
    gap: 12px;
    padding: 8px 12px;
  }
}

@media (max-width: 360px) {
  .keyboard {
    grid-template-columns: repeat(7, 1fr);
  }

  .letter-slot {
    width: 22px;
    height: 34px;
    font-size: 1.1rem;
  }
}
