:root {
  color-scheme: light;
  --bg: #eef3f5;
  --panel: #ffffff;
  --panel-soft: #f7fafb;
  --line: #cfdce3;
  --line-strong: #9bb0bd;
  --text: #18242c;
  --muted: #60717d;
  --brand: #167567;
  --brand-dark: #105b51;
  --warn-bg: #fff5dc;
  --warn-line: #e5c36c;
  --danger: #b43b3b;
  --ok: #1f7a4e;
  --shadow: 0 8px 22px rgba(18, 38, 48, 0.08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  border-radius: 7px;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--brand);
}

button:disabled {
  color: #9aa8b0;
  cursor: not-allowed;
  background: #eef2f4;
}

button.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  font-weight: 700;
}

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

a {
  color: var(--brand-dark);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 7px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.button-link.secondary-link {
  background: #fff;
  color: var(--text);
  border-color: var(--line-strong);
}

.disabled-link {
  pointer-events: none;
  opacity: 0.45;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  height: 68px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
}

.brand-subtitle,
.small-muted {
  color: var(--muted);
  font-size: 13px;
}

.user-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  background: var(--warn-line);
}

.status-dot.ok {
  background: var(--ok);
}

.quota {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 132px;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-inner {
  padding: 16px;
}

.step-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.step-link {
  text-align: left;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 48px;
  border-color: var(--line);
}

.step-link[aria-current="step"] {
  background: #e4f4f0;
  border-color: var(--brand);
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #dfe8ed;
  font-weight: 800;
  color: #34444e;
}

.step-link[aria-current="step"] .step-num {
  background: var(--brand);
  color: #fff;
}

.main-stage {
  min-height: calc(100vh - 100px);
}

.stage-header {
  padding: 24px 24px 10px;
}

.eyebrow {
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
}

.lead {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 760px;
  line-height: 1.55;
}

.stage-body {
  padding: 16px 24px 24px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
}

.field textarea {
  min-height: 280px;
  resize: vertical;
  line-height: 1.55;
}

.metrics-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.metric {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 130px;
}

.metric strong {
  display: block;
  font-size: 20px;
}

.metric-link {
  color: inherit;
  text-decoration: none;
}

.metric-link:hover {
  border-color: var(--brand);
  background: #e4f4f0;
}

.metric-disabled {
  opacity: .55;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.project-choice {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
  align-items: start;
}

.choice-panel,
.review-tools,
.timing-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 16px;
}

.project-list {
  display: grid;
  gap: 10px;
  max-height: 480px;
  overflow: auto;
}

.project-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  min-height: 56px;
}

.voice-card,
.session-item,
.download-item,
.chunk-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.voice-card.selected {
  border-color: var(--brand);
  background: #e4f4f0;
}

.voice-card h3 {
  font-size: 16px;
  margin-bottom: 4px;
}

.voice-card .actions {
  margin-top: 10px;
}

.notice {
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
  border-radius: 8px;
  padding: 12px;
  line-height: 1.45;
}

.notice.error {
  border-color: #d77a7a;
  background: #fff0f0;
  color: #6f1e1e;
}

.notice.success {
  border-color: #77bd98;
  background: #e8f7ef;
  color: #174d34;
}

.progress-shell {
  height: 12px;
  background: #e3ebef;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-shell.animated {
  position: relative;
}

.progress-shell.animated::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.65), transparent);
  animation: shimmer 1.7s linear infinite;
}

.progress-bar {
  height: 100%;
  background: var(--brand);
  width: 0%;
  transition: width .25s ease;
}

.work-card {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  background: #f8fbfc;
  border-radius: 8px;
  padding: 18px;
}

.work-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.work-orbit {
  width: 68px;
  height: 68px;
  position: relative;
  border: 2px solid #d4e5eb;
  border-radius: 50%;
  animation: rotate 3.2s linear infinite;
}

.work-orbit span {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--brand);
}

.work-orbit span:nth-child(1) { top: -6px; left: 28px; }
.work-orbit span:nth-child(2) { right: 3px; bottom: 8px; opacity: .65; }
.work-orbit span:nth-child(3) { left: 3px; bottom: 8px; opacity: .35; }

.pipeline {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.pipeline-step {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 10px;
  min-height: 72px;
}

.pipeline-step span {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #dfe8ed;
  font-weight: 800;
  margin-bottom: 8px;
}

.pipeline-step.done {
  border-color: #86bea6;
  background: #edf8f2;
}

.pipeline-step.done span {
  background: var(--ok);
  color: #fff;
}

.pipeline-step.active {
  border-color: var(--brand);
  background: #e4f4f0;
  box-shadow: 0 0 0 3px rgba(22, 117, 103, .12);
}

.pipeline-step.active span {
  background: var(--brand);
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}

.audio-player {
  width: 100%;
  margin: 16px 0;
}

.compact-player {
  margin: 6px 0;
}

.chunk-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.review-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(420px, 1.2fr);
  gap: 16px;
  align-items: start;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.guided-review-list {
  max-height: 620px;
}

.chunk-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.review-chunk {
  width: 100%;
  text-align: left;
  cursor: grab;
}

.review-chunk.selected {
  border-color: var(--brand);
  background: #e4f4f0;
}

.review-chunk.playing {
  border-color: #2f86a6;
  box-shadow: inset 4px 0 0 #2f86a6;
}

.review-chunk:active {
  cursor: grabbing;
}

.review-editor,
.review-player-panel,
.timing-panel {
  display: grid;
  gap: 14px;
}

.chunk-row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.mini-action {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
  background: #fff;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
}

.mini-action:hover {
  border-color: var(--brand);
  background: #e4f4f0;
}

.chunk-textarea {
  min-height: 150px;
}

.chunk-textarea.is-dirty,
.field textarea.is-dirty {
  border-color: var(--warn-line);
  box-shadow: 0 0 0 3px rgba(229, 195, 108, .22);
}

.timing-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
}

.timing-panel {
  margin-top: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 24, 38, .42);
}

.modal-card {
  width: min(880px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(8, 24, 38, .22);
  padding: 18px;
}

.chunk-edit-modal {
  width: min(1040px, 100%);
}

.modal-header,
.modal-title-row,
.modal-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2,
.modal-section h3 {
  margin: 0 0 6px;
}

.modal-section {
  display: grid;
  gap: 10px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.modal-footer {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.icon-button {
  min-width: 40px;
  width: 40px;
  padding: 8px;
  font-weight: 700;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.choice-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f8fbfd;
  cursor: pointer;
}

.choice-pill.selected {
  border-color: var(--brand);
  background: #e4f4f0;
}

.choice-pill.disabled {
  opacity: .55;
  cursor: not-allowed;
}

.timing-chunk-picker {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  padding-right: 4px;
}

.timing-chunk-option {
  display: grid;
  grid-template-columns: auto 48px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fbfd;
}

.timing-chunk-option.selected {
  border-color: var(--brand);
  background: #e4f4f0;
}

.timing-chunk-option span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-actions {
  gap: 8px;
}

.karaoke-line {
  min-height: 54px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  line-height: 1.8;
}

.large-karaoke {
  min-height: 150px;
  font-size: 20px;
  line-height: 2.05;
}

.now-reading-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.now-reading-card strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.karaoke-word {
  display: inline-block;
  padding: 1px 3px;
  border-radius: 4px;
}

.karaoke-word.active {
  background: #d9efe9;
  color: var(--brand-dark);
  font-weight: 800;
}

.zip-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 16px;
  margin-bottom: 16px;
}

.download-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.side-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.side-section:last-child {
  border-bottom: 0;
}

.session-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.session-item {
  width: 100%;
  text-align: left;
  min-height: 64px;
}

.empty {
  color: var(--muted);
  padding: 10px 0;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
}

.login-card .brand-title {
  font-size: 26px;
}

.hidden {
  display: none !important;
}

.mobile-install {
  display: none;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .right-rail {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  :root {
    --shadow: 0 4px 14px rgba(18, 38, 48, 0.08);
  }

  body {
    font-size: 15px;
    background: #edf4f6;
  }

  button,
  .button-link {
    min-height: 46px;
    border-radius: 9px;
  }

  .topbar {
    height: auto;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 12px 14px;
    position: sticky;
    top: 0;
    z-index: 30;
  }

  .brand-title {
    font-size: 18px;
  }

  .brand-subtitle {
    font-size: 12px;
  }

  .user-strip {
    justify-content: stretch;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .user-strip:last-child {
    grid-template-columns: 1fr 1fr;
  }

  .quota {
    min-width: 0;
    padding: 7px 9px;
  }

  .quota strong {
    font-size: 15px;
    line-height: 1.15;
  }

  .mobile-install {
    display: inline-flex;
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .layout > .panel:first-child {
    order: 1;
    position: sticky;
    top: 126px;
    z-index: 18;
  }

  .main-stage {
    order: 2;
    min-height: auto;
  }

  .right-rail {
    order: 3;
  }

  .layout[data-current-step="progetto"] .right-rail {
    display: none;
  }

  .panel {
    border-radius: 10px;
    box-shadow: var(--shadow);
  }

  .step-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .step-link {
    flex: 0 0 108px;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
    min-height: 58px;
    padding: 8px;
    scroll-snap-align: start;
  }

  .step-link strong {
    font-size: 14px;
  }

  .step-link .small-muted {
    display: none;
  }

  .stage-header {
    padding: 18px 16px 6px;
  }

  .stage-body {
    padding: 12px 16px 18px;
  }

  h1 {
    font-size: 30px;
    line-height: 1.08;
  }

  h2 {
    font-size: 23px;
  }

  .lead {
    font-size: 15px;
    line-height: 1.45;
  }

  .field textarea {
    min-height: 260px;
    font-size: 16px;
  }

  .metrics-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric {
    min-width: 0;
  }

  .metric strong {
    font-size: 18px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .actions > button,
  .actions > .button-link {
    width: 100%;
  }

  .chunk-row {
    grid-template-columns: 1fr;
  }

  .project-choice,
  .review-grid,
  .timing-grid {
    grid-template-columns: 1fr;
  }

  .choice-panel,
  .review-tools,
  .timing-panel {
    padding: 14px;
  }

  .project-list,
  .session-list {
    max-height: 360px;
  }

  .project-row,
  .session-item,
  .voice-card {
    min-height: 58px;
  }

  .voice-grid,
  .download-list {
    grid-template-columns: 1fr;
  }

  .review-grid {
    gap: 12px;
  }

  .guided-review-list,
  .chunk-list {
    max-height: 58vh;
  }

  .chunk-row-actions {
    justify-content: space-between;
  }

  .large-karaoke {
    min-height: 108px;
    font-size: 17px;
    line-height: 1.8;
  }

  .modal-backdrop {
    padding: 0;
    align-items: stretch;
  }

  .modal-card,
  .chunk-edit-modal {
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding: 14px;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding-bottom: 10px;
  }

  .timing-chunk-option {
    grid-template-columns: auto 42px minmax(0, 1fr);
  }

  .timing-chunk-option small {
    grid-column: 2 / -1;
  }

  .side-section {
    padding: 14px;
  }

  .side-section h2 {
    font-size: 22px;
  }

  .work-card,
  .pipeline {
    grid-template-columns: 1fr;
  }

  .pipeline {
    gap: 6px;
  }

  .pipeline-step {
    min-height: auto;
  }
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

@keyframes rotate {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}
