@import "fonts/fonts.css";

:root {
  /* Yak Identity v2 color palette */
  --yak-ground: #f1ece2;        /* page ground */
  --yak-paper: #fbf9f4;         /* editor, boxes */
  --yak-sand: #e8e2d5;          /* container panel */
  --yak-sand-2: #efeae0;        /* panel inner */
  --yak-rule: #d8d0bf;          /* 1px rules */
  --yak-rule-2: #d6cdbc;        /* panel outer border */
  --yak-grey: #7a7368;          /* secondary text */
  --yak-grey-3: #b9b2a4;
  --yak-ink: #3a3733;           /* primary ink */
  --yak-vermilion: #c3401f;     /* accent, recording state, mark stop */
  --yak-vermilion-tint: #f2d8cd;
  --yak-vermilion-wash: #f7e9e3;
  --yak-unsure: #c87a1e;        /* light warm amber for unsure words */

  /* Typography */
  --font-serif: "Source Serif 4", Georgia, serif;
  --font-mono: "Source Code Pro", ui-monospace, monospace;

  /* Elevation and radii */
  --shadow-panel: 0 10px 34px rgba(58, 55, 51, 0.10);
  --shadow-hero: 0 14px 44px rgba(58, 55, 51, 0.16);
  --radius-btn: 2px;
  --radius-panel: 6px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-short: 180ms;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--yak-ground);
  background-image: radial-gradient(rgba(0, 0, 0, 0.032) 0.6px, transparent 0.7px);
  background-size: 5px 5px;
  color: var(--yak-ink);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Page wrapper filling viewport */
.app-layout {
  max-width: 980px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 20px min(4vw, 36px) 24px;
}

/* Header with baseline alignment */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--yak-ink);
  margin-bottom: 18px;
  flex-shrink: 0;
}

.brand-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.diane-mark {
  width: 38px;
  height: 26px;
  transform: translateY(3px);
  display: block;
}

.brand-title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 26px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--yak-ink);
}

.brand-title .dot {
  color: var(--yak-vermilion);
}

.brand-host {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 13px;
  line-height: 1;
  color: var(--yak-grey);
}

#load {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1;
  color: var(--yak-grey);
  white-space: nowrap;
}

/* Main workspace */
.main-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

/* Panel surface filling vertical space */
.panel {
  background: var(--yak-sand);
  border: 1px solid var(--yak-rule-2);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  z-index: 2;
  transition: box-shadow var(--duration-short) var(--ease-out);
}

.panel:focus-within {
  box-shadow: var(--shadow-hero);
}

/* Editor */
/* The editor takes whatever height is left after the fixed header, footer and mic dock */
#editor {
  flex: 1;
  min-height: 96px;
  height: auto;
  overflow-y: auto;
  background: var(--yak-paper);
  padding: 24px 28px;
  font-family: var(--font-serif);
  font-size: 19.5px;
  line-height: 1.6;
  color: var(--yak-ink);
  outline: none;
  word-break: break-word;
  white-space: pre-wrap;
  user-select: text;
  transition: font-size 250ms ease;
}

@media (prefers-reduced-motion: reduce) {
  #editor {
    transition: none;
  }
}

#editor[data-fontstep="0"] {
  font-size: 19.5px;
}

#editor[data-fontstep="1"] {
  font-size: 17.5px;
}

#editor[data-fontstep="2"] {
  font-size: 15.5px;
}

#editor[data-fontstep="3"] {
  font-size: 15px;
}

#editor:focus-visible {
  outline: 2px solid var(--yak-ink);
  outline-offset: -2px;
}

#editor:empty::before {
  content: attr(data-placeholder);
  color: var(--yak-grey);
  opacity: 0.75;
  pointer-events: none;
}

/* Committed, tentative and preview text */
#editor span.committed {
  color: var(--yak-ink);
}

#editor span.tentative {
  color: var(--yak-grey);
  opacity: 0.65;
  transition: opacity var(--duration-short) var(--ease-out);
}

#editor span.preview {
  color: var(--yak-grey);
  opacity: 0.65;
  transition: color var(--duration-short) var(--ease-out), opacity var(--duration-short) var(--ease-out);
}

#editor span.listening {
  color: var(--yak-grey);
  opacity: 0.65;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

#editor span.uncertain,
span.uncertain {
  text-decoration: underline 2px;
  text-decoration-color: var(--yak-unsure);
  text-underline-offset: 3px;
  text-decoration-skip-ink: auto;
}

/* Stopping shimmer on active dictation spans */
@keyframes stopping-shimmer {
  0% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.95;
  }
  100% {
    opacity: 0.45;
  }
}

body[data-state="stopping"] #editor span.committed,
body[data-state="stopping"] #editor span.tentative,
body[data-state="stopping"] #editor span.preview {
  animation: stopping-shimmer 1.4s ease-in-out infinite;
}

body[data-state="stopping"] #editor span.tentative {
  animation-delay: 0.25s;
}

body[data-state="stopping"] #editor span.preview {
  animation-delay: 0.5s;
}

.dictation-final-fade {
  display: inline;
}

/* Panel footer strip */
.panel-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 12px 24px 14px;
  background: var(--yak-sand);
  border-top: 1px solid var(--yak-rule);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--yak-grey);
  flex-shrink: 0;
}

.word-count {
  white-space: nowrap;
}

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

/* Buttons */
.btn-action {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.2;
  padding: 4px 10px;
  border: 1px solid var(--yak-ink);
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--yak-ink);
  cursor: pointer;
  transition: background var(--duration-short) var(--ease-out),
              color var(--duration-short) var(--ease-out),
              border-color var(--duration-short) var(--ease-out);
}

.btn-action:hover {
  background: var(--yak-ink);
  color: var(--yak-ground);
}

.btn-action:focus-visible {
  outline: 2px solid var(--yak-ink);
  outline-offset: 2px;
}

.btn-action.copied {
  background: var(--yak-ink);
  color: var(--yak-ground);
  border-color: var(--yak-ink);
}

.btn-action.copy-failed {
  border-color: var(--yak-vermilion);
  color: var(--yak-vermilion);
}

#copy {
  min-width: 5.5em;
  text-align: center;
}

/* Controls section: mic dock (below card) */
.controls-area {
  position: relative;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 0 20px;
  flex-shrink: 0;
}

/* Fixed-size stage for mic and visual rings */
.mic-stage {
  position: relative;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.visual-halo {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.halo-soft {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(195, 64, 31, 0.45) 0%, rgba(195, 64, 31, 0.12) 55%, transparent 72%);
  filter: blur(8px);
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity;
}

.halo-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}

.halo-ring-1 {
  width: 106px;
  height: 106px;
  border: 1.5px solid var(--yak-vermilion);
}

.halo-ring-2 {
  width: 126px;
  height: 126px;
  border: 1px dashed var(--yak-vermilion);
}

/* Queued breath animation */
@keyframes queued-breathe {
  0% { transform: translate(-50%, -50%) scale(0.96); opacity: 0.35; }
  50% { transform: translate(-50%, -50%) scale(1.08); opacity: 0.75; }
  100% { transform: translate(-50%, -50%) scale(0.96); opacity: 0.35; }
}

body[data-state="queued"] .halo-ring-1 {
  border-color: var(--yak-ink);
  opacity: 0.5;
  animation: queued-breathe 2s ease-in-out infinite;
}

/* Mic button (88-96px hero button on desktop) */
#mic {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 2px solid var(--yak-ink);
  background: var(--yak-paper);
  color: var(--yak-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background var(--duration-short) var(--ease-out),
              border-color 150ms var(--ease-out),
              color var(--duration-short) var(--ease-out);
  z-index: 4;
}

body[data-state="idle"] #mic:hover {
  border-color: var(--yak-vermilion);
}

body[data-state="idle"] #mic:hover .mic-icon {
  transform: scale(1.06);
}

#mic:active .mic-icon {
  transform: scale(0.94);
}

#mic:focus-visible {
  outline: 2px solid var(--yak-ink);
  outline-offset: 4px;
}

.mic-icon {
  width: 36px;
  height: 36px;
  display: block;
  transition: transform 120ms var(--ease-out);
}

/* Starting mic state: neutral pulsing ring visibly distinct from live recording */
body[data-state="connecting"]:not([data-cue="speak-now"]) #mic,
body[data-state="queued"]:not([data-cue="speak-now"]) #mic,
body[data-state="reconnecting"]:not([data-cue="speak-now"]) #mic,
body[data-state="recording"]:not([data-cue="speak-now"]) #mic {
  border-color: var(--yak-rule);
  background: var(--yak-ground);
  color: var(--yak-grey);
  box-shadow: 0 0 0 3px var(--yak-sand);
  animation: mic-starting-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-starting-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--yak-sand); }
  50% { box-shadow: 0 0 0 9px rgba(180, 175, 165, 0.45); }
}

/* Capturing / live active states */
body[data-cue="speak-now"] #mic,
body[data-state="queued"][data-cue="speak-now"] #mic,
body[data-state="recording"][data-cue="speak-now"] #mic,
body[data-state="connecting"][data-cue="speak-now"] #mic,
body[data-state="reconnecting"][data-cue="speak-now"] #mic {
  border-color: var(--yak-vermilion);
  background: var(--yak-vermilion);
  color: var(--yak-paper);
}

body[data-cue="speak-now"] #mic .mic-icon {
  animation: speak-now-pop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes speak-now-pop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

body[data-state="recording"] #mic:focus-visible,
body[data-state="connecting"] #mic:focus-visible,
body[data-state="queued"] #mic:focus-visible,
body[data-state="reconnecting"] #mic:focus-visible {
  outline-color: var(--yak-vermilion);
}

/* Spinner for stopping */
.stopping-spinner {
  display: none;
  width: 38px;
  height: 38px;
  border: 2px solid var(--yak-sand);
  border-top-color: var(--yak-ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Level meter canvas in dock */
.level-meter {
  display: block;
  width: 160px;
  height: 8px;
  margin: 8px auto 4px;
  pointer-events: none;
  position: relative;
  z-index: 1;
}

body[data-state="stopping"] #mic .mic-icon {
  display: none;
}

body[data-state="stopping"] #mic .stopping-spinner {
  display: block;
}

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

/* Status block holding hints, timer row, and status rows */
.status-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 36em;
  min-height: 76px;
  height: 76px;
  box-sizing: border-box;
}

/* Quiet idle hint under mic */
.mic-hint {
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.35;
  color: var(--yak-grey);
  opacity: 0.85;
  margin: 0;
  user-select: none;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hint-tap {
  display: none;
}

.hint-click {
  display: inline;
  text-align: center;
}

@media (hover: none) and (pointer: coarse) {
  .hint-click {
    display: none;
  }
  .hint-tap {
    display: inline;
    text-align: center;
  }
}

.kbd-hint {
  display: none;
  font-family: var(--font-mono);
  font-size: 14.5px;
  line-height: 1.35;
  color: var(--yak-grey);
  opacity: 0.85;
  text-align: center;
  margin-top: 2px;
}

body:not([data-state="idle"]) .mic-hint {
  display: none !important;
}

body[data-state="idle"] #timer {
  display: none !important;
}

body[data-state="idle"] .status-row {
  min-height: 24px;
  height: 24px;
}

/* Timer readout */
#timer {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.2;
  color: var(--yak-grey);
  letter-spacing: 0.04em;
  min-height: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#timer:empty {
  visibility: hidden;
}

/* Status row containing status message and retry button */
.status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 48px;
  height: 48px;
  width: 100%;
}

/* Status line */
#status {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 15.5px;
  line-height: 1.45;
  color: var(--yak-grey);
  text-align: center;
  max-width: 34em;
  text-wrap: balance;
}

#status .mono {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 13.5px;
}

body[data-state="error"] #status {
  color: var(--yak-vermilion);
}

body[data-state="error"][data-error-kind="calm"] #status {
  color: var(--yak-grey);
}

/* Retry button placed next to error status */
.btn-retry {
  border-color: var(--yak-vermilion);
  color: var(--yak-vermilion);
  padding: 3px 10px;
}

.btn-retry:hover {
  background: var(--yak-vermilion);
  color: var(--yak-ground);
}

body[data-state="error"][data-error-kind="calm"] .btn-retry {
  border-color: var(--yak-ink);
  color: var(--yak-ink);
}

body[data-state="error"][data-error-kind="calm"] .btn-retry:hover {
  background: var(--yak-ink);
  color: var(--yak-ground);
}

body:not([data-state="error"]) #retry {
  display: none !important;
}

body[data-state="error"] #retry {
  display: inline-flex !important;
}

/* Hidden debug panel */
#debug-panel {
  display: none;
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--yak-sand);
  border: 1px solid var(--yak-rule);
  border-radius: var(--radius-panel);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--yak-grey);
  flex-shrink: 0;
}

body.debug-visible #debug-panel {
  display: block;
}

.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 16px;
  margin-bottom: 10px;
}

.debug-log {
  max-height: 120px;
  overflow-y: auto;
  border-top: 1px solid var(--yak-rule);
  padding-top: 8px;
  font-size: 11px;
}

/* Compact dock: short or narrow viewports put the status beside the mic */
@media (max-height: 880px), (max-width: 700px) {
  .app-layout {
    padding-top: 14px;
    padding-bottom: 10px;
  }

  .app-header {
    margin-bottom: 12px;
    padding-bottom: 10px;
  }

  .main-content {
    gap: 10px;
  }

  .controls-area {
    display: grid;
    grid-template-columns: auto minmax(0, 24em);
    grid-template-areas:
      "mic status"
      "meter status";
    justify-content: center;
    align-items: center;
    column-gap: 18px;
    row-gap: 0;
    margin-top: 0;
    padding: 0 0 4px;
  }

  .mic-stage {
    grid-area: mic;
    width: 96px;
    height: 96px;
  }

  #mic {
    width: 64px;
    height: 64px;
  }

  .mic-icon,
  .stopping-spinner {
    width: 28px;
    height: 28px;
  }

  .halo-soft {
    width: 78px;
    height: 78px;
  }

  .halo-ring-1 {
    width: 72px;
    height: 72px;
  }

  .halo-ring-2 {
    width: 88px;
    height: 88px;
  }

  .status-block {
    grid-area: status;
    align-items: flex-start;
    align-self: center;
    justify-content: center;
    max-width: none;
    min-height: 0;
    height: auto;
    max-height: 104px;
    overflow: hidden;
  }

  .level-meter {
    grid-area: meter;
    justify-self: center;
    width: 84px;
    height: 6px;
    margin: 0;
  }

  .mic-hint {
    align-items: flex-start;
    text-align: left;
    font-size: 14px;
  }

  .hint-click,
  .hint-tap,
  .kbd-hint {
    text-align: left;
  }

  .kbd-hint {
    font-size: 13px;
  }

  #timer {
    justify-content: flex-start;
  }

  .status-row,
  body[data-state="idle"] .status-row {
    justify-content: flex-start;
    flex-wrap: nowrap;
    min-height: 40px;
    height: 40px;
  }

  #status {
    text-align: left;
    font-size: 14.5px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* Mobile dock (<700px) */
@media (max-width: 700px) {
  .app-layout {
    height: 100dvh;
    padding: 16px 14px 0;
  }

  .app-header {
    margin-bottom: 12px;
    padding-bottom: 10px;
  }

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

  .diane-mark {
    width: 32px;
    height: 22px;
  }

  .main-content {
    flex: 1;
    min-height: 0;
    gap: 0;
  }

  .panel {
    flex: 1;
    min-height: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
  }

  #editor {
    flex: 1;
    min-height: 120px;
    height: auto;
    max-height: none;
    padding: 16px 18px;
    font-size: 18px;
  }

  #editor[data-fontstep="0"] {
    font-size: 18px;
  }

  #editor[data-fontstep="1"] {
    font-size: 16px;
  }

  #editor[data-fontstep="2"] {
    font-size: 15px;
  }

  #editor[data-fontstep="3"] {
    font-size: 15px;
  }

  .controls-area {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    margin-top: 0;
    background: var(--yak-ground);
    border-top: 1px solid var(--yak-rule);
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 10;
  }

  .mic-stage {
    width: 96px;
    height: 96px;
  }

  #mic {
    width: 62px;
    height: 62px;
  }

  .mic-icon {
    width: 28px;
    height: 28px;
  }

  .stopping-spinner {
    width: 28px;
    height: 28px;
  }

  .halo-soft {
    width: 76px;
    height: 76px;
  }

  .halo-ring-1 {
    width: 70px;
    height: 70px;
  }

  .halo-ring-2 {
    width: 84px;
    height: 84px;
  }

  .level-meter {
    width: 84px;
    height: 6px;
  }
}

/* Motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
