.app {
  width: min(96vw, 920px);
  margin: 1.1rem auto 2rem;
  padding: 0 0.45rem;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 1rem + 1.2vw, 2rem);
}

h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.panel {
  content-visibility: auto;
  contain-intrinsic-size: 180px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.stats p {
  margin: 0;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
}

.strikes {
  display: inline-flex;
  gap: 0.3rem;
  margin: 0 0.35rem 0 0.15rem;
}

.strike-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.strike-dot.is-on {
  border-color: #8f2d2d;
  background: #c84f4f;
  color: #fff5f5;
}

.play-area {
  position: relative;
  overflow: hidden;
  text-align: center;
  transition: background-color 160ms ease;
}

.play-area.celebrate {
  animation: celebrate-burst 900ms ease;
}

.play-area.flash-good {
  animation: flash-good 240ms ease;
}

.play-area.flash-bad {
  animation: flash-bad 240ms ease;
}

.label {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-weight: 700;
}

.milestone-banner {
  margin: 0 0 0.55rem;
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
}

#book-name {
  margin: 0.5rem 0 0.9rem;
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2.2rem);
}

.progress-copy {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-weight: 700;
}

.progress-track {
  width: 100%;
  height: 0.85rem;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--start-bg);
  transition: width 240ms ease;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  max-width: 460px;
  margin: 0 auto;
}

button {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.62rem 0.8rem;
  min-height: 2.85rem;
  cursor: pointer;
  font-weight: 700;
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

button:focus-visible {
  outline: 3px solid #d8a64c;
  outline-offset: 2px;
}

#old-btn,
#new-btn {
  min-width: 0;
  width: 100%;
}

#old-btn {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
  box-shadow: var(--shadow-soft);
}

#new-btn {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
  box-shadow: var(--shadow-soft);
}

#daily-status,
#daily-score,
#daily-best,
#daily-streak {
  margin: 0 0 0.35rem;
}

.setting {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  margin-right: 0.7rem;
  flex-wrap: wrap;
}

.setting select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font: inherit;
}

.setting-help {
  font-size: 0.78rem;
  line-height: 1.25;
  color: #6a5f50;
  font-weight: 600;
  width: 100%;
}

.bottom-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.8rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 0.1rem;
}

.start-action {
  margin-left: 0;
  order: -1;
  background: var(--start-bg);
  color: #f8fffb;
  border-color: var(--start-border);
  box-shadow: var(--start-shadow);
}

.bottom-actions button {
  white-space: nowrap;
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
  box-shadow: var(--shadow-soft);
}

.bottom-actions .action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  white-space: nowrap;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.62rem 0.8rem;
  min-height: 2.85rem;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.btn-icon {
  margin-right: 0.2rem;
}

.graphics-fab {
  position: fixed;
  right: 0.8rem;
  bottom: 0.8rem;
  z-index: 160;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 800;
  border: 1px solid #2f6f50;
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  background: linear-gradient(180deg, #3a8a63 0%, #2b6b4d 100%);
  color: #f8fffb;
  box-shadow: 0 0.4rem 1rem rgba(16, 44, 32, 0.35);
}

@media (max-width: 640px) {
  .graphics-fab {
    right: 0.6rem;
    bottom: 0.6rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.feedback {
  min-height: 1.4rem;
  margin: 0.85rem 0 0;
  font-weight: 700;
}

.feedback.good {
  color: var(--accent);
}

.feedback.bad {
  color: #b13f3f;
}

.miss-x {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(5rem, 24vw, 10rem);
  font-weight: 900;
  color: rgba(196, 37, 37, 0.96);
  text-shadow: 0 0 1.5rem rgba(128, 14, 14, 0.45);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
  z-index: 3;
}

.miss-x.show {
  animation: miss-x-burst 420ms ease-out;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 8;
}

body.screen-flash-good::before {
  animation: screen-flash-good 220ms ease;
}

body.screen-flash-bad::before {
  animation: screen-flash-bad 220ms ease;
}

@keyframes flash-good {
  0% {
    background-color: rgba(64, 158, 97, 0.22);
  }
  100% {
    background-color: transparent;
  }
}

@keyframes flash-bad {
  0% {
    background-color: rgba(191, 72, 72, 0.2);
  }
  100% {
    background-color: transparent;
  }
}

@keyframes miss-x-burst {
  0% {
    opacity: 0;
    transform: scale(0.65);
  }
  22% {
    opacity: 1;
    transform: scale(1.08);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

@keyframes celebrate-burst {
  0% {
    box-shadow: 0 0 0 rgba(215, 169, 73, 0);
    transform: scale(1);
  }
  35% {
    box-shadow: 0 0 1rem rgba(215, 169, 73, 0.55);
    transform: scale(1.01);
  }
  100% {
    box-shadow: 0 0 0 rgba(215, 169, 73, 0);
    transform: scale(1);
  }
}

@keyframes screen-flash-good {
  0% {
    opacity: 0.32;
    background: #44b868;
  }
  100% {
    opacity: 0;
    background: transparent;
  }
}

@keyframes screen-flash-bad {
  0% {
    opacity: 0.28;
    background: #c64545;
  }
  100% {
    opacity: 0;
    background: transparent;
  }
}

#best-score {
  margin: 0 0 0.4rem;
}

#best-score-today {
  margin: 0 0 0.4rem;
}

.high-score-list {
  margin: 0;
  padding-left: 1.2rem;
}

.high-score-list li {
  margin-bottom: 0.25rem;
}

#review-empty {
  margin: 0 0 0.4rem;
}

.missed-list {
  margin: 0;
  padding-left: 1.2rem;
}

.missed-list li {
  margin-bottom: 0.25rem;
}

.tour-highlight {
  position: relative;
  z-index: 121;
  box-shadow: 0 0 0 3px #d8a64c, 0 0.8rem 1.2rem rgba(39, 32, 22, 0.18);
  border-radius: 10px;
}

.tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(28, 24, 18, 0.58);
  display: grid;
  place-items: end center;
  padding: 1rem;
}

.tour-card {
  width: min(96vw, 520px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
}

.tour-card h2 {
  margin: 0 0 0.35rem;
  color: var(--accent);
}

.tour-card p {
  margin: 0 0 0.65rem;
  color: #5f5446;
  line-height: 1.35;
}

.tour-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
}

.tour-primary {
  background: var(--accent);
  color: #f8fffb;
  border-color: #2b5f45;
}

.tour-toggle {
  margin-left: auto;
  font-size: 0.82rem;
  color: #5f5446;
}

.summary-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(33, 28, 21, 0.62);
  padding: 1rem;
}

.summary-modal[hidden] {
  display: none;
}

.summary-card {
  width: min(96vw, 560px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: var(--shadow-deep);
}

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

.summary-header h2 {
  margin: 0;
}

.settings-modal {
  position: fixed;
  top: 5rem;
  right: 1rem;
  z-index: 130;
  width: min(92vw, 420px);
  display: block;
  background: transparent;
  padding: 0;
}

.settings-modal[hidden] {
  display: none;
}

.settings-card {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: var(--shadow-deep);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.6rem;
}

.settings-header h2 {
  margin: 0;
}

.popup-close {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 999px;
  font-size: 1.25rem;
  line-height: 1;
  background: var(--bg);
  color: var(--text);
}

.settings-grid {
  display: grid;
  gap: 0.6rem;
}

.settings-subpanel {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  background: var(--bg);
}

.settings-subpanel h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.scores-modal {
  position: fixed;
  top: 5rem;
  right: 1rem;
  z-index: 130;
  width: min(92vw, 420px);
  display: block;
  background: transparent;
  padding: 0;
}

.scores-modal[hidden] {
  display: none;
}

@media (max-width: 640px) {
  .settings-modal {
    right: auto;
    left: 50%;
    top: 4.4rem;
    transform: translateX(-50%);
    width: min(94vw, 420px);
  }

  .scores-modal {
    right: auto;
    left: 50%;
    top: 4.4rem;
    transform: translateX(-50%);
    width: min(94vw, 420px);
  }

  .start-action {
    margin-left: 0;
  }
}

.summary-mode {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-weight: 700;
}

.summary-list {
  margin: 0;
  padding-left: 1.2rem;
}

.summary-list li {
  margin-bottom: 0.3rem;
}

.summary-actions {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

#summary-play-again-btn {
  background: var(--start-bg);
  color: #ffffff;
  border-color: var(--start-border);
}

#summary-practice-btn,
#summary-home-btn {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
}

@media (max-width: 640px) {
  .app {
    padding: 0 0.45rem;
  }

  .top {
    flex-direction: row;
    align-items: flex-start;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .bottom-actions {
    align-items: center;
    flex-direction: row;
  }

  .summary-actions {
    flex-direction: column;
  }
}

/* --- Arcade Polish Additions --- */

.visual-timer-track {
  width: 100%;
  height: 0.65rem;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 0 0 1rem;
  border: 1px solid var(--line);
}

.visual-timer-fill {
  height: 100%;
  width: 100%;
  background: var(--start-bg);
  transition: width 100ms linear, background-color 200ms ease;
}

.visual-timer-fill.warning {
  background: #d8a64c;
}

.visual-timer-fill.danger {
  background: #c84f4f;
}

.visual-timer-fill.pulse {
  animation: timer-pulse 300ms alternate infinite;
}

@keyframes timer-pulse {
  0% { opacity: 1; }
  100% { opacity: 0.5; }
}

.combo-display {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.2rem;
  font-weight: 800;
  color: #d8a64c;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  z-index: 10;
  pointer-events: none;
}

.combo-display.combo-pulse {
  animation: combo-bump 300ms ease;
}

@keyframes combo-bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.floating-text-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.floating-text {
  position: absolute;
  font-size: 1.5rem;
  font-weight: 900;
  color: #44b868;
  text-shadow: 0 2px 4px rgba(0,0,0,0.4);
  animation: float-up-fade 800ms ease-out forwards;
}

.floating-text.bonus {
  color: #d8a64c;
  font-size: 1.8rem;
}

@keyframes float-up-fade {
  0% { opacity: 1; transform: translateY(0) scale(0.8); }
  10% { transform: translateY(-5px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-40px) scale(1); }
}

.screen-shake {
  animation: shake 300ms ease-in-out;
}

@keyframes shake {
  0% { transform: translate(1px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -2px) rotate(-1deg); }
  20% { transform: translate(-3px, 0px) rotate(1deg); }
  30% { transform: translate(3px, 2px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(1deg); }
  50% { transform: translate(-1px, 2px) rotate(-1deg); }
  60% { transform: translate(-3px, 1px) rotate(0deg); }
  70% { transform: translate(3px, 1px) rotate(-1deg); }
  80% { transform: translate(-1px, -1px) rotate(1deg); }
  90% { transform: translate(1px, 2px) rotate(0deg); }
  100% { transform: translate(1px, -2px) rotate(-1deg); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
