:root {
  color-scheme: light;
  --background: #f3ede2;
  --surface: rgba(255, 253, 248, 0.9);
  --surface-strong: #fffdf8;
  --ink: #302d29;
  --muted: #756f67;
  --line: #ddd3c3;
  --accent: #956342;
  --accent-dark: #774b31;
  --accent-soft: #eadac7;
  --danger: #a13f38;
  --shadow: 0 24px 70px rgba(78, 59, 39, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.8), transparent 32rem),
    radial-gradient(circle at 90% 90%, rgba(221, 201, 174, 0.45), transparent 30rem),
    var(--background);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100% - 32px, 920px);
  margin: 0 auto;
  padding: 42px 0 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent);
  font-size: 32px;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 27px;
  font-weight: 500;
}

.brand p {
  margin-top: 2px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

.card {
  border: 1px solid rgba(149, 99, 66, 0.14);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.setup-view {
  padding: clamp(26px, 6vw, 58px);
}

.intro {
  max-width: 600px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-family: system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.intro h2 {
  max-width: 520px;
  margin: 0;
  font-size: clamp(32px, 5vw, 50px);
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.06;
}

.intro > p:last-child {
  margin: 20px 0 0;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  line-height: 1.55;
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 0 0 24px;
}

.library-section {
  margin-top: 38px;
}

.section-label {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
}

.library-list {
  display: grid;
  gap: 10px;
}

.library-item {
  display: flex;
  width: 100%;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-strong);
  color: var(--ink);
  text-align: left;
  transition: 150ms ease;
}

.library-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.library-item strong,
.library-item small {
  display: block;
  font-family: system-ui, sans-serif;
}

.library-item strong {
  font-size: 16px;
}

.library-item small {
  margin-top: 4px;
  color: var(--muted);
}

.library-item > span:last-child {
  color: var(--accent);
  font-size: 24px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 30px 0 20px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 12px;
}

.divider::before,
.divider::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.file-picker {
  display: grid;
  min-height: 178px;
  padding: 24px;
  cursor: pointer;
  border: 1px dashed #c8b49d;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.42);
  transition: 160ms ease;
}

.file-picker:hover,
.file-picker:focus-within,
.file-picker.has-file {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.file-icon {
  align-self: start;
  color: var(--accent);
  font-size: 32px;
}

.file-label {
  align-self: end;
  margin-top: 20px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 13px;
}

.file-picker strong {
  margin-top: 5px;
  overflow: hidden;
  font-family: system-ui, sans-serif;
  font-size: 16px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button {
  min-height: 50px;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  transition: 150ms ease;
}

.button:focus-visible,
.text-button:focus-visible {
  outline: 3px solid rgba(149, 99, 66, 0.3);
  outline-offset: 3px;
}

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

.button:not(:disabled):active {
  transform: scale(0.97);
}

.primary {
  background: var(--accent);
  color: white;
}

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

.secondary {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
}

.secondary:hover:not(:disabled) {
  border-color: #c5ae93;
  background: var(--accent-soft);
}

.start-button {
  width: 100%;
  font-family: system-ui, sans-serif;
  font-weight: 700;
}

.message {
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

.error {
  color: var(--danger);
}

.session-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  font-family: system-ui, sans-serif;
}

.text-button {
  padding: 7px 0;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
}

.audio-title {
  max-width: 55%;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.practice-settings {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  font-family: system-ui, sans-serif;
}

.mode-switch {
  display: flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.6);
}

.mode-button,
.voice-button {
  min-height: 40px;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
}

.mode-button {
  padding: 0 16px;
}

.mode-button.active {
  background: var(--accent);
  color: white;
}

.delay-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.delay-control select {
  min-height: 40px;
  padding: 0 28px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--ink);
}

.voice-button {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.voice-button > span:first-child {
  color: #aaa39a;
  font-size: 9px;
}

.voice-button.listening {
  border-color: #a85c4f;
  color: #8b3e34;
}

.voice-button.listening > span:first-child {
  color: #c34e40;
  animation: voice-pulse 1.4s ease-in-out infinite;
}

.voice-help {
  margin: -7px 0 16px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 12px;
  text-align: right;
}

.voice-help.voice-error {
  color: var(--danger);
}

@keyframes voice-pulse {
  50% {
    opacity: 0.3;
    transform: scale(1.4);
  }
}

.phrase-card {
  min-height: 560px;
  padding: clamp(26px, 6vw, 58px);
}

.progress-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 13px;
}

.progress-track {
  height: 3px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--line);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 250ms ease;
}

.phrase-status {
  margin-top: clamp(54px, 10vw, 90px);
}

.phrase-text {
  display: flex;
  min-height: 150px;
  align-items: center;
  margin: 0;
  font-size: clamp(28px, 5vw, 46px);
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.controls {
  display: grid;
  grid-template-columns: 74px 74px minmax(130px, 1fr) 74px;
  gap: 12px;
  align-items: center;
  margin-top: 52px;
}

.icon-button {
  display: grid;
  height: 66px;
  place-content: center;
  gap: 1px;
  font-family: system-ui, sans-serif;
}

.icon-button > span {
  font-size: 21px;
  line-height: 1;
}

.icon-button small {
  font-size: 10px;
}

.play-button {
  display: flex;
  height: 66px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: system-ui, sans-serif;
  font-weight: 750;
}

.keyboard-help {
  margin: 20px 0 0;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 640px) {
  body.session-active {
    overflow: hidden;
  }

  .app-shell {
    width: min(100% - 20px, 920px);
    padding-top: 22px;
  }

  body.session-active .app-shell {
    width: 100%;
    height: 100dvh;
    padding: 0;
  }

  body.session-active .brand {
    display: none;
  }

  .brand {
    margin-bottom: 22px;
  }

  .file-grid {
    grid-template-columns: 1fr;
  }

  .file-picker {
    min-height: 130px;
  }

  .practice-view:not([hidden]) {
    display: flex;
    height: 100dvh;
    flex-direction: column;
  }

  .session-topbar {
    min-height: 45px;
    flex: 0 0 auto;
    margin: 0;
    padding: 7px 14px 3px;
  }

  .practice-settings {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 7px;
    margin: 0;
    padding: 6px 10px 9px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .practice-settings::-webkit-scrollbar {
    display: none;
  }

  .mode-switch,
  .delay-control,
  .voice-button {
    flex: 0 0 auto;
  }

  .mode-button {
    padding: 0 12px;
  }

  .voice-button {
    margin-left: auto;
  }

  .voice-help {
    flex: 0 0 auto;
    margin: 0;
    padding: 0 14px 7px;
    font-size: 11px;
    text-align: left;
  }

  .phrase-card {
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
    flex-direction: column;
    padding: 20px 18px max(16px, env(safe-area-inset-bottom));
    overflow-y: auto;
    border-radius: 24px 24px 0 0;
  }

  .phrase-text {
    min-height: 0;
    flex: 1 1 auto;
    padding: 18px 0;
    font-size: clamp(24px, 7vw, 34px);
  }

  .phrase-status {
    margin-top: 24px;
  }

  .controls {
    grid-template-columns: repeat(3, 1fr);
    flex: 0 0 auto;
    margin-top: 18px;
  }

  .play-button {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .icon-button,
  .play-button {
    height: 58px;
  }

  .keyboard-help {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
