:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --accent: #2d6a4f;
  --accent-hover: #1b4332;
  --heard: #40916c;
  --partial: #e9c46a;
  --border: #d8d2c8;
  --shadow: 0 8px 24px rgba(26, 26, 26, 0.08);
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --touch-min: 48px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(160deg, #f4f1ec 0%, #e8efe9 100%);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  overflow-x: hidden;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.app__header {
  margin-bottom: 1rem;
}

.app__header h1 {
  margin: 0;
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  font-weight: 700;
}

.script-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  margin-bottom: 1rem;
}

@media (min-width: 640px) {
  .script-buttons {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
  }
}

.script-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 5.5rem;
  padding: 0.65rem 0.4rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.script-btn__title {
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.script-btn__status {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 100%;
  height: 1.25em;
  min-height: 1.25em;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--muted);
}

.script-btn__status:empty::before {
  content: "\00a0";
}

.script-btn--heard .script-btn__status {
  color: var(--heard);
}

.script-btn--partial .script-btn__status {
  color: #7c5e10;
}

.script-btn--heard:not(.script-btn--active) {
  border-color: #b7e4c7;
}

.script-btn--partial:not(.script-btn--active) {
  border-color: #f4d58d;
}

.script-btn:active {
  transform: scale(0.98);
}

.script-btn--active {
  border-color: var(--accent);
  background: #e8f5ee;
}

.player {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

@media (min-width: 640px) {
  .player {
    padding: 1.25rem;
  }
}

.player__active {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.player__voice-hint {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--muted);
}

.player__voice-hint--ok {
  color: #1b4332;
}

.player__voice-hint--warn {
  color: #7c5e10;
}

.player__diag {
  display: none;
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: #fff8f0;
  border: 1px solid #e9c46a;
  font-size: 0.82rem;
}

.player__diag--visible {
  display: block;
}

.player__diag--error {
  display: block;
  background: #fff5f5;
  border-color: #e76f51;
}

.player__diag--ok {
  background: #f0faf4;
  border-color: #95d5b2;
}

.player__diag-title {
  margin: 0 0 0.35rem;
  font-weight: 700;
}

.player__diag-list {
  margin: 0;
  padding-left: 1.1rem;
}

.player__diag-list li {
  margin: 0.2rem 0;
}

.player__diag-list li[data-level="error"] {
  color: #9b2226;
  font-weight: 600;
}

.player__diag-list li[data-level="warn"] {
  color: #7c5e10;
}

.player__diag-list li[data-level="ok"] {
  color: #1b4332;
}

.player__controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.btn {
  min-height: var(--touch-min);
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:not(:disabled):active {
  background: var(--accent-hover);
}

.progress-seek {
  display: block;
  width: 100%;
  height: 36px;
  margin: 0 0 0.5rem;
  cursor: pointer;
  accent-color: var(--accent);
}

@media (min-width: 640px) {
  .progress-seek {
    height: 28px;
  }
}

.progress-seek:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.player__position {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.player__preview {
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.85rem;
  border-left: 4px solid var(--accent);
  background: #f8faf8;
  font-size: 0.85rem;
  color: var(--text);
  max-height: 30vh;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}

.player__preview mark {
  background: #ffe066;
  padding: 0 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
