/* Note Taker: single stylesheet, no framework. Tokens match tanoitcorp.com. */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-raised: #ffffff;
  --bg-sunken: #fafafa;
  --border: #e5e5e5;
  --line-soft: #f0f0f0;
  --text: #0a0a0a;
  --text-muted: #525252;
  --accent: #2563eb;
  --accent-2: #06b6d4;
  --accent-strong: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #a16207;
  --radius: 16px;
  --font: Inter, system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

/*
 * The UA's `[hidden] { display: none }` is a user-agent rule, so any author
 * rule that sets `display` beats it — `.btn { display: inline-flex }` would
 * otherwise keep hidden buttons on screen. The app toggles visibility with
 * `element.hidden` throughout, so this has to win.
 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.6rem;
}
h3 {
  font-size: 0.92rem;
  margin: 1rem 0 0.4rem;
}
a {
  color: var(--accent);
}

.muted {
  color: var(--text-muted);
}
.small {
  font-size: 0.83rem;
}
.warn {
  color: var(--warn);
}
.error {
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin: 0.6rem 0 0;
  font-size: 0.88rem;
  white-space: pre-wrap;
}

/* --- Top bar ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
  padding-top: calc(0.7rem + env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.brand-dot.is-recording {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.2);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 9px rgba(220, 38, 38, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand-dot.is-recording {
    animation: none;
  }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chip {
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

/* --- Layout ------------------------------------------------------------- */

.view {
  max-width: 880px;
  margin: 0 auto;
  padding: 1rem;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px -12px rgba(0, 0, 0, 0.08);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.center-card {
  max-width: 460px;
  margin: 3rem auto;
  text-align: center;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem;
  margin-bottom: 1rem;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.5rem;
  border-radius: 999px;
  cursor: pointer;
}

.tab.is-active {
  background: var(--text);
  color: #fff;
}

/* --- Controls ----------------------------------------------------------- */

.btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.5rem 1.1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:hover:not(:disabled) {
  border-color: #a3a3a3;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-lg {
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
}
.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #262626;
  border-color: #262626;
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 600;
}
.btn-ghost {
  background: transparent;
}
.btn:focus-visible,
.tab:focus-visible,
.input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.input {
  font: inherit;
  font-size: 0.9rem;
  background: var(--bg-sunken);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.45rem 0.6rem;
  min-width: 0;
}

.field {
  display: grid;
  grid-template-columns: 190px 1fr;
  align-items: center;
  gap: 0.7rem;
  margin: 0.55rem 0;
}

.field > span {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.field-note {
  margin: -0.3rem 0 0.6rem;
}

@media (max-width: 560px) {
  .field {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
}

/* --- Source picker ------------------------------------------------------ */

.sources {
  border: 0;
  padding: 0;
  margin: 0.4rem 0 0;
  display: grid;
  gap: 0.5rem;
}
.sources legend {
  padding: 0;
  margin-bottom: 0.35rem;
}

.source {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "radio title" "radio desc";
  gap: 0 0.6rem;
  align-items: start;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--bg-sunken);
}

.source:has(input:checked) {
  border-color: var(--accent-strong);
  background: #eff6ff;
}
.source input {
  grid-area: radio;
  margin-top: 0.35rem;
  accent-color: var(--accent);
}
.source-title {
  grid-area: title;
  font-weight: 600;
  font-size: 0.9rem;
}
.source-desc {
  grid-area: desc;
  color: var(--text-muted);
  font-size: 0.83rem;
}

/* --- Recording ---------------------------------------------------------- */

.timer {
  font-family: var(--mono);
  font-size: 1.15rem;
  margin-left: auto;
}

.meter {
  height: 6px;
  background: var(--bg-sunken);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.8rem 0 0.5rem;
}

.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 80ms linear;
}

/* --- Transcript --------------------------------------------------------- */

.transcript {
  max-height: 45vh;
  overflow-y: auto;
}

.utterance {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 0.75rem;
  padding: 0.4rem 0;
  border-top: 1px solid var(--border);
}

.utterance:first-child {
  border-top: 0;
}

@media (max-width: 560px) {
  .utterance {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }
}

.utterance-who {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.utterance-who .at {
  color: var(--text-muted);
  font-weight: 400;
  font-family: var(--mono);
}
.utterance-who button {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
  text-decoration: underline dotted;
}

.utterance-text {
  white-space: pre-wrap;
}
.utterance.is-pending .utterance-text {
  color: var(--text-muted);
  font-style: italic;
}

/* --- Lists -------------------------------------------------------------- */

.list {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.list-item-main {
  min-width: 0;
}
.list-item-title {
  font-weight: 600;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}
.list-item-sub {
  color: var(--text-muted);
  font-size: 0.82rem;
}
.list-item-actions {
  display: flex;
  gap: 0.4rem;
  flex: none;
}

.banner {
  background: #fefce8;
  border: 1px solid #fde68a;
  color: var(--warn);
  border-radius: 9px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  margin-top: 0.6rem;
}

/* --- Pairing ------------------------------------------------------------ */

.code-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin: 0.6rem 0;
}

.pair-code {
  font-family: var(--mono);
  font-size: 1.5rem;
  letter-spacing: 0.2em;
  padding: 0.4rem 0 0.4rem 0.2em;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: block;
}

.center-card .btn-lg {
  margin: 0.5rem auto;
}
.center-card .controls {
  justify-content: center;
}

/* --- Markdown output ---------------------------------------------------- */

.markdown h3 {
  color: var(--accent);
}
.markdown ul {
  margin: 0.3rem 0 0.8rem;
  padding-left: 1.15rem;
}
.markdown li {
  margin: 0.15rem 0;
}
.markdown p {
  margin: 0.3rem 0 0.8rem;
}

audio {
  width: 100%;
  margin: 0.6rem 0;
}

/* --- Toast -------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.87rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 50;
  max-width: min(90vw, 520px);
}

/* --- Pairing fallback ---------------------------------------------------- */

.fallback {
  margin: 0.9rem 0;
  text-align: left;
}

.fallback > summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.87rem;
}

.fallback #pair-token {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

/* A file input styled as a button: the label is the control, the input is
   hidden inside it (`hidden` alone would also hide it from the picker click,
   so keep it in the flow but out of sight). */
.btn > input[type="file"][hidden] {
  display: none !important;
}

/* --- Tanoit Corp header (same as tanoitcorp.com) ------------------------- */

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.logo-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.topbar-main {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-width: 0;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 20px;
}
.nav-links a {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
}
.nav-links a:hover {
  color: var(--text);
}
.menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.topbar-pill {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
@media (max-width: 767px) {
  .menu-btn {
    display: grid;
  }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 8px 16px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .topbar.open .nav-links {
    display: flex;
  }
  .nav-links a {
    padding: 12px 0;
    font-size: 16px;
  }
}

.chip {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 560px) {
  .chip {
    display: none;
  }
}
