/* ==========================================
   精肉コード暗記アプリ - スタイル
   ========================================== */

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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1f2b47;
  --bg-input: #0f1729;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a8b8;
  --text-muted: #6b7280;
  --accent: #4a90d9;
  --accent-hover: #5ea3ef;
  --accent-glow: rgba(74, 144, 217, 0.3);
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.12);
  --error: #f87171;
  --error-bg: rgba(248, 113, 113, 0.12);
  --warning: #fbbf24;
  --border: #2d3a54;
  --border-focus: #4a90d9;
  --keypad-bg: #243352;
  --keypad-hover: #2e4068;
  --keypad-active: #1b2940;
  --btn-action: #4a90d9;
  --btn-action-hover: #5ea3ef;
  --btn-issue: #2ecc71;
  --btn-issue-hover: #3ddb80;
  --btn-disabled: #2a3550;
  --btn-disabled-text: #4a5568;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --transition: 0.2s ease;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

/* --- App Container --- */
.app {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 12px 12px env(safe-area-inset-bottom, 12px);
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  margin-bottom: 8px;
}

.header__title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.header__score {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: 20px;
}

.header__score strong {
  color: var(--accent);
}

/* --- Mode Tabs --- */
.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  padding: 4px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.mode-tab {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.mode-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* --- Settings --- */
.settings {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.setting-group label {
  white-space: nowrap;
}

.setting-group select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  outline: none;
}

.setting-group select:focus {
  border-color: var(--border-focus);
}

.order-toggle {
  border: none;
  background: var(--bg-input);
  color: var(--text-primary);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}

.order-toggle:hover {
  background: var(--keypad-hover);
}

.order-toggle .icon {
  margin-right: 2px;
}

/* --- Question Area --- */
.question-area {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  margin-bottom: 10px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.question-area__progress {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.question-area__name {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  line-height: 1.3;
  color: var(--text-primary);
  min-height: 3.2rem;
}

.timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  transition: width 0.1s linear;
  border-radius: 0 2px 0 0;
}

.timer-bar.warning {
  background: var(--warning);
}

.timer-bar.danger {
  background: var(--error);
}

/* --- Input Display --- */
.input-display {
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  margin-bottom: 10px;
  transition: border-color var(--transition);
}

.input-display.focused {
  border-color: var(--border-focus);
}

.input-display__value {
  font-size: 2.8rem;
  font-weight: 700;
  font-family: 'SF Mono', 'Menlo', 'Courier New', monospace;
  letter-spacing: 0.3em;
  color: var(--text-primary);
  min-height: 3.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-display__placeholder {
  color: var(--text-muted);
  font-size: 1.2rem;
  font-weight: 400;
  letter-spacing: 0.1em;
}

/* --- Keypad --- */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.keypad__btn {
  height: 56px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--keypad-bg);
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.keypad__btn:hover {
  background: var(--keypad-hover);
}

.keypad__btn:active {
  background: var(--keypad-active);
  transform: scale(0.96);
}

.keypad__btn--clear {
  grid-column: span 2;
  background: #3d2020;
  color: var(--error);
  font-size: 1.3rem;
  font-weight: 700;
}

.keypad__btn--clear:hover {
  background: #4d2a2a;
}

.keypad__btn--clear:active {
  background: #2d1818;
}

/* --- Action Buttons --- */
.actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.action-btn {
  flex: 1;
  height: 56px;
  border: none;
  border-radius: var(--radius);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.05em;
}

.action-btn:disabled {
  background: var(--btn-disabled);
  color: var(--btn-disabled-text);
  cursor: not-allowed;
}

.action-btn--bui {
  background: var(--btn-action);
  color: #fff;
}

.action-btn--bui:not(:disabled):hover {
  background: var(--btn-action-hover);
}

.action-btn--bui:not(:disabled):active {
  transform: scale(0.97);
}

.action-btn--issue {
  background: var(--btn-issue);
  color: #fff;
}

.action-btn--issue:not(:disabled):hover {
  background: var(--btn-issue-hover);
}

.action-btn--issue:not(:disabled):active {
  transform: scale(0.97);
}

/* --- Feedback Overlay --- */
.feedback-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.feedback-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.feedback-overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.feedback-overlay__content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 32px;
  animation: feedbackPop 0.3s ease;
}

.feedback-overlay__icon {
  font-size: 5rem;
  margin-bottom: 16px;
  line-height: 1;
}

.feedback-overlay__text {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.feedback-overlay__answer {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.feedback-overlay__answer strong {
  color: var(--success);
  font-size: 1.3rem;
}

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

.feedback-overlay.correct .feedback-overlay__icon {
  color: var(--success);
}

.feedback-overlay.correct .feedback-overlay__text {
  color: var(--success);
}

.feedback-overlay.incorrect .feedback-overlay__icon {
  color: var(--error);
}

.feedback-overlay.incorrect .feedback-overlay__text {
  color: var(--error);
}

/* --- Complete Screen --- */
.complete-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  background: var(--bg-primary);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.complete-screen.show {
  opacity: 1;
  pointer-events: auto;
}

.complete-screen__emoji {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: bounce 0.6s ease;
}

.complete-screen__title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.complete-screen__score {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.complete-screen__score strong {
  color: var(--accent);
  font-size: 1.4rem;
}

.complete-screen__rate {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 28px;
}

.complete-screen__rate.perfect {
  color: var(--success);
}

.complete-screen__rate.great {
  color: var(--accent);
}

.complete-screen__rate.good {
  color: var(--warning);
}

.complete-screen__rate.retry {
  color: var(--error);
}

.restart-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 48px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
}

.restart-btn:hover {
  background: var(--accent-hover);
}

.restart-btn:active {
  transform: scale(0.96);
}

/* --- Animations --- */
@keyframes feedbackPop {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes bounce {

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

  40% {
    transform: translateY(-20px);
  }

  60% {
    transform: translateY(-8px);
  }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  display: none;
}

/* --- Responsive tweaks for very small screens --- */
@media (max-height: 640px) {
  .question-area {
    padding: 14px 12px;
  }

  .question-area__name {
    font-size: 2rem;
  }

  .input-display {
    padding: 10px;
  }

  .input-display__value {
    font-size: 2.2rem;
    min-height: 2.8rem;
  }

  .keypad__btn {
    height: 46px;
    font-size: 1.3rem;
  }

  .action-btn {
    height: 46px;
    font-size: 1rem;
  }
}

@media (min-height: 800px) {
  .keypad__btn {
    height: 64px;
    font-size: 1.6rem;
  }

  .action-btn {
    height: 62px;
    font-size: 1.3rem;
  }
}