:root {
  color-scheme: light;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #d7dee8;
  --paper: #ffffff;
  --field: #f8fafc;
  --blue: #1687d9;
  --green: #1c9a73;
  --red: #cc4a4a;
  --amber: #e4a11b;
  --shadow: 0 20px 50px rgba(30, 41, 59, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #eef3f8;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(22, 135, 217, 0.12), transparent 36%),
    linear-gradient(225deg, rgba(28, 154, 115, 0.12), transparent 42%),
    #eef3f8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button,
select,
textarea {
  font: inherit;
}

button,
select {
  touch-action: manipulation;
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(22, 135, 217, 0.28);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
  display: flex;
}

.workspace {
  width: min(1220px, 100%);
  min-height: calc(100vh - 48px);
  margin: auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
}

.topbar,
.dictation-stage,
.mic-panel,
.editor-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(215, 222, 232, 0.9);
  box-shadow: var(--shadow);
}

.topbar {
  border-radius: 8px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(135deg, var(--blue), var(--green));
  box-shadow: inset 0 -10px 22px rgba(0, 0, 0, 0.12);
}

.brand-mark span {
  font-size: 23px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.1vw, 2rem);
  line-height: 1.1;
}

p {
  margin: 5px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.select-wrap {
  height: 44px;
  min-width: 148px;
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.select-wrap select {
  min-width: 0;
  height: 28px;
  padding: 0 32px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}

.select-wrap select:focus {
  border-color: var(--blue);
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.icon-button.danger:hover {
  border-color: var(--red);
  color: var(--red);
}

svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dictation-stage {
  min-height: 0;
  border-radius: 8px;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
  gap: 18px;
}

.mic-panel,
.editor-panel {
  border-radius: 8px;
}

.mic-panel {
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.signal-orb {
  position: relative;
  width: min(100%, 240px);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  place-items: center;
}

#pulseCanvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.mic-button {
  position: absolute;
  width: 92px;
  height: 92px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--blue);
  box-shadow: 0 16px 32px rgba(22, 135, 217, 0.3);
  cursor: pointer;
}

.mic-button svg {
  width: 34px;
  height: 34px;
}

.mic-button.listening {
  background: var(--red);
  box-shadow: 0 16px 32px rgba(204, 74, 74, 0.32);
}

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

.status-stack {
  display: grid;
  gap: 4px;
  text-align: center;
}

.status-stack strong {
  font-size: 1.15rem;
}

.status-stack span {
  color: var(--muted);
}

.editor-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.editor-toolbar {
  min-height: 62px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--field);
}

.mode-switch {
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  gap: 4px;
  background: var(--paper);
}

.mode-button {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.mode-button.active {
  color: #ffffff;
  background: var(--blue);
}

.legacy-select {
  width: min(230px, 100%);
}

.editor-textarea {
  width: 100%;
  min-height: 420px;
  height: 100%;
  padding: 22px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: var(--paper);
  font-size: clamp(1.1rem, 1.6vw, 1.35rem);
  line-height: 1.7;
}

.editor-textarea[hidden] {
  display: none;
}

.editor-textarea::placeholder {
  color: #94a3b8;
}

.legacy-output {
  letter-spacing: 0.01em;
}

.legacy-font-kaputa {
  font-family: kaputadotcom, "KaputaUnicode", "Kaputa", serif;
}

.legacy-font-dl-manel {
  font-family: "DL-Manel-bold", "DL Manel", "DL-Manel", serif;
}

.legacy-font-tipitaka {
  font-family: "Tipitaka_Sinhala1", "Tipitaka Sinhala1", serif;
}

.transcript-footer {
  min-height: 54px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  background: var(--field);
}

#interimText {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--amber);
}

#saveState {
  flex: 0 0 auto;
}

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

  .workspace {
    min-height: calc(100vh - 24px);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .select-wrap {
    flex: 1 1 auto;
  }

  .dictation-stage {
    grid-template-columns: 1fr;
  }

  .mic-panel {
    grid-template-columns: minmax(150px, 180px) 1fr;
    align-items: center;
  }

  .editor-textarea {
    min-height: 42vh;
  }
}

@media (max-width: 680px) {
  html,
  body {
    height: 100%;
  }

  body {
    background: var(--paper);
    overscroll-behavior-y: none;
  }

  .app-shell {
    height: 100svh;
    min-height: 100svh;
    padding: 0;
    display: block;
  }

  @supports (height: 100dvh) {
    .app-shell {
      height: 100dvh;
      min-height: 100dvh;
    }
  }

  .workspace {
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    gap: 0;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar,
  .dictation-stage,
  .mic-panel,
  .editor-panel {
    border-color: rgba(215, 222, 232, 0.78);
    box-shadow: none;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    min-height: 68px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    border-width: 0 0 1px;
    border-radius: 0;
    background: rgba(255, 255, 255, 0.96);
  }

  .brand-lockup {
    gap: 10px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand-mark span {
    font-size: 20px;
  }

  h1 {
    font-size: 1.18rem;
  }

  p {
    max-width: 82vw;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
  }

  .topbar-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 8;
    max-width: 100vw;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(215, 222, 232, 0.9);
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -14px 32px rgba(30, 41, 59, 0.12);
    backdrop-filter: blur(18px);
  }

  .topbar-actions .select-wrap {
    flex: 1 1 auto;
    height: 48px;
    min-width: 0;
  }

  .topbar-actions .select-wrap span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .topbar-actions .select-wrap select {
    width: 100%;
    height: 48px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
  }

  .icon-button {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border-radius: 8px;
  }

  .dictation-stage {
    min-height: 0;
    height: 100%;
    padding: 10px 10px calc(78px + env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    background: #eef3f8;
    overflow: hidden;
  }

  .mic-panel,
  .editor-panel {
    min-width: 0;
    background: var(--paper);
  }

  .mic-panel {
    padding: 10px;
    border-radius: 8px;
    display: grid;
    grid-template-columns: 74px minmax(0, 1fr);
    align-items: center;
    gap: 8px 10px;
  }

  .signal-orb {
    width: 74px;
  }

  .mic-button {
    width: 56px;
    height: 56px;
    box-shadow: 0 10px 20px rgba(22, 135, 217, 0.24);
  }

  .mic-button svg {
    width: 25px;
    height: 25px;
  }

  .status-stack {
    min-width: 0;
    text-align: left;
  }

  .status-stack strong {
    font-size: 1rem;
  }

  .status-stack span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
  }

  .editor-panel {
    min-height: 0;
    border-radius: 8px;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .editor-toolbar {
    min-width: 0;
    min-height: auto;
    padding: 8px;
    gap: 8px;
    align-items: stretch;
    flex-direction: column;
  }

  .mode-switch {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .mode-button {
    min-width: 0;
    min-height: 38px;
    padding: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.86rem;
  }

  .legacy-select {
    width: 100%;
    min-width: 0;
  }

  .legacy-select select {
    height: 38px;
    padding-left: 8px;
    font-size: 0.82rem;
  }

  .editor-textarea {
    min-height: 0;
    padding: 14px;
    font-size: 1.08rem;
    line-height: 1.65;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .transcript-footer {
    min-height: 42px;
    padding: 9px 12px;
    gap: 8px;
    font-size: 0.78rem;
  }
}

@media (max-width: 560px) {
  .mic-panel {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .signal-orb {
    grid-row: auto;
  }

  .mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .transcript-footer {
    align-items: center;
    flex-direction: row;
  }
}

@media (max-width: 420px) {
  .dictation-stage {
    padding-inline: 8px;
  }

  .topbar {
    padding-inline: 12px;
  }

  .mic-panel {
    grid-template-columns: 66px minmax(0, 1fr);
  }

  .signal-orb {
    width: 66px;
  }

  .mic-button {
    width: 52px;
    height: 52px;
  }

  .topbar-actions {
    padding-inline: 8px;
    gap: 6px;
  }

  .topbar-actions .select-wrap select {
    padding-left: 9px;
    padding-right: 26px;
    font-size: 0.92rem;
  }

  .icon-button {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
  }

  .transcript-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}
