:root {
  color-scheme: light;
  --paper: #f7f4ef;
  --panel: rgba(255, 253, 248, 0.94);
  --ink: #231f1a;
  --muted: #736c64;
  --line: #ddd4c8;
  --accent: #087f5b;
  --accent-soft: #e6f4ee;
  --warm: #b35c1e;
  --warm-soft: #fff0df;
  --dark: #28231f;
  --shadow: 0 14px 36px rgba(50, 42, 32, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(10, 12, 13, 0.76), rgba(10, 12, 13, 0.46) 46%, rgba(10, 12, 13, 0.34)),
    linear-gradient(180deg, rgba(10, 12, 13, 0.55), rgba(10, 12, 13, 0.18) 42%, rgba(10, 12, 13, 0.66)),
    url("assets/black-divine-background.jpg") center center / cover fixed no-repeat,
    #15120f;
  color: var(--ink);
  font-family:
    Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
  backdrop-filter: saturate(1.03);
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 4px 0 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #f2c46f;
  font-size: 0.78rem;
  font-weight: 800;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.65);
}

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

h1 {
  font-size: 2rem;
  color: #fffaf0;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}

h2 {
  font-size: 1rem;
}

.actions,
.input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.button:hover:not(:disabled) {
  filter: brightness(0.96);
}

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

.button.secondary {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}

.button.dark {
  background: var(--dark);
  border-color: var(--dark);
}

.button.compact {
  min-width: 68px;
  flex: 0 0 auto;
}

.controls-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(320px, 1.15fr);
  gap: 16px;
  margin-bottom: 16px;
}

.upload-zone,
.filter-panel,
.speaker-panel,
.result-panel,
.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.upload-zone {
  display: grid;
  align-content: center;
  min-height: 156px;
  padding: 24px;
  cursor: pointer;
  outline: 2px dashed transparent;
  outline-offset: -10px;
  transition: background 160ms ease, outline-color 160ms ease;
}

.upload-zone.is-dragging {
  background: var(--accent-soft);
  outline-color: var(--accent);
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.upload-title {
  display: block;
  font-size: 1.12rem;
  font-weight: 850;
}

.upload-meta {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.filter-panel {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.field-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

input[type="search"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr)) minmax(220px, 1.5fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  min-height: 74px;
  padding: 14px 16px;
}

.stat-value {
  display: block;
  font-size: 1.36rem;
  font-weight: 900;
  white-space: nowrap;
}

.stat-value.small {
  font-size: 1rem;
  line-height: 1.35;
  white-space: normal;
}

.stat-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.speaker-panel,
.result-panel {
  min-height: 440px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.speaker-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 360px);
  min-height: 360px;
  overflow: auto;
  padding: 12px;
}

.speaker-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
}

.speaker-button:hover,
.speaker-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.speaker-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.speaker-count {
  min-width: 42px;
  border-radius: 999px;
  background: var(--warm-soft);
  color: var(--warm);
  padding: 3px 8px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 900;
}

.result-panel {
  overflow: hidden;
}

.message-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 360px);
  min-height: 360px;
  overflow: auto;
  padding: 14px;
}

.message-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px 14px;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.message-speaker {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.message-text {
  margin: 0;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.empty-state.is-hidden,
.message-list.is-hidden {
  display: none;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  border-radius: 8px;
  background: var(--dark);
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .actions {
    align-items: stretch;
  }

  .topbar,
  .controls-grid,
  .main-grid,
  .stats-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

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

  .stat.wide {
    grid-column: 1 / -1;
  }

  .speaker-list,
  .message-list {
    max-height: none;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 1.55rem;
  }

  .actions,
  .input-row {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .button {
    width: 100%;
  }
}
