:root {
  color-scheme: light;
  --page: #fff;
  --surface: #f9f9f9;
  --sidebar: #f2f2f2;
  --ink: #202020;
  --muted: #737373;
  --line: #e5e5e5;
  --accent: #635bff;
  --accent-hover: #5145e5;
  --sans: Inter, 'Segoe UI', Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-width: 280px;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: .875rem/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, select, textarea { font: inherit; }
button, select { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.skip-link {
  position: fixed;
  z-index: 10;
  inset: 0 auto auto 0;
  padding: .65rem 1rem;
  transform: translateY(-145%);
  background: var(--ink);
  color: white;
}

.skip-link:focus { transform: translateY(0); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-shell {
  --sidebar-width: 256px;
  display: grid;
  min-height: 100vh;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar-collapsed .app-shell { --sidebar-width: 68px; }

.site-header {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  overflow: auto;
  border-right: 1px solid #e6e6e6;
  background: var(--sidebar);
}

.site-header-inner {
  display: flex;
  min-height: 100%;
  flex-direction: column;
}

.sidebar-top {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
  padding: 0 1rem;
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: .65rem;
  color: inherit;
  text-decoration: none;
}

.profile-mark {
  display: grid;
  flex: none;
  place-items: center;
  background: #202020;
  color: #fff;
  font-weight: 750;
}

.brand-mark {
  display: block;
  flex: none;
}

.brand-copy, .profile-copy {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -.037em;
  white-space: nowrap;
}

.profile-copy span {
  color: var(--muted);
  font-size: .72rem;
}

#sidebar-toggle { flex: none; }
.sidebar-collapsed #sidebar-toggle .icon { transform: rotate(180deg); }

.sidebar-group { margin-bottom: 1.75rem; }

.sidebar-label {
  margin: 1rem 1.5rem .4rem;
  color: #666;
  font-size: .78rem;
  font-weight: 500;
  text-transform: uppercase;
}

.header-actions {
  display: grid;
  gap: .12rem;
  padding-inline: .75rem;
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .5rem .8rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: .875rem;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.icon {
  display: block;
  flex: none;
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  min-width: 34px;
  min-height: 34px;
  padding: .35rem;
}

.button-quiet:hover:not(:disabled) { background: #eaeaea; }

.header-actions .button {
  position: relative;
  width: 100%;
  justify-content: flex-start;
  gap: .64rem;
  padding-inline: .75rem;
  font-weight: 500;
}

.header-actions .nav-action:hover:not(:disabled) { background: #e9e9e9; }

.header-actions .nav-current {
  overflow: hidden;
  background: #e6e6e6;
  color: #1d1d1d;
  font-weight: 600;
}

.header-actions .nav-current::before {
  position: absolute;
  inset: .35rem auto .35rem 0;
  width: 2px;
  border-radius: 5px;
  background: #242424;
  content: '';
}

.sidebar-bottom {
  margin-top: auto;
  padding-block: .55rem;
}

.sidebar-profile {
  display: flex;
  min-height: 70px;
  align-items: center;
  gap: .65rem;
  padding: .6rem 1rem;
  border-top: 1px solid #e4e4e4;
}

.profile-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e0e0e0;
  color: #2c2c2c;
  font-size: .85rem;
}

.profile-copy > :first-child { font-weight: 650; }

.sidebar-collapsed :is(.brand-copy, .sidebar-label, .profile-copy) {
  display: none;
}

.sidebar-collapsed .header-actions .button span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sidebar-collapsed .sidebar-top {
  flex-direction: column;
  gap: .45rem;
  justify-content: center;
  padding: .6rem .3rem;
}

.sidebar-collapsed .header-actions .button { justify-content: center; }

.workspace {
  min-width: 0;
  padding: 24px;
}

.usage-card {
  position: relative;
  display: grid;
  min-height: 82px;
  grid-template-columns: minmax(0, 1.25fr) minmax(160px, 447px) minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  margin-bottom: 16px;
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--page);
}

.usage-summary {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.usage-summary > .icon {
  width: 1.25rem;
  height: 1.25rem;
}

.usage-title, .usage-words, .usage-percent, .usage-note { margin: 0; }

.usage-title { font-weight: 650; }
.usage-words, .usage-note { color: var(--muted); font-size: .8125rem; }
.usage-words strong { margin-right: .15rem; color: var(--ink); font-size: 1.125rem; }

.usage-details {
  position: relative;
  display: grid;
  justify-self: end;
  justify-items: end;
  gap: .12rem;
  text-align: right;
}

.usage-percent {
  color: #167c45;
  font-size: .9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.usage-info {
  position: absolute;
  top: 50%;
  right: .8rem;
  transform: translateY(-50%);
  color: var(--muted);
}

.usage-card:has(.usage-info) .usage-details { margin-right: 2rem; }
.usage-info:hover { background: #f2f2f2; }

.usage-progress, #character-progress {
  display: block;
  width: 100%;
  height: 8px;
  appearance: none;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #eaeaea;
  color: #242424;
}

.usage-progress { height: 10px; }
#character-progress { height: 5px; }

.usage-progress::-webkit-progress-bar, #character-progress::-webkit-progress-bar { background: #eaeaea; }
.usage-progress::-webkit-progress-value, #character-progress::-webkit-progress-value { border-radius: 999px; background: #242424; }
.usage-progress::-moz-progress-bar, #character-progress::-moz-progress-bar { border-radius: 999px; background: #242424; }

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

.editor-column { display: flex; min-width: 0; flex-direction: column; }

.editor-pane {
  display: flex;
  min-width: 0;
  height: clamp(330px, calc(100dvh - 266px), 1040px);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--page);
}

.pane-heading {
  flex: none;
  padding: .7rem 1.5rem;
  border-bottom: 1px solid #efefef;
}

.pane-heading-row, .character-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem .8rem;
}

.pane-heading-row { min-height: 22px; }
.source-pane .pane-heading { min-height: 88px; }

.pane-extra {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .12rem;
  margin-inline-start: auto;
  opacity: 0;
  transition: opacity 150ms ease;
}

.source-pane:is(:hover, :focus-within) .pane-extra { opacity: 1; }
.pane-actions { display: inline-flex; gap: .12rem; }

.pane-extra .button {
  min-height: 27px;
  gap: .3rem;
  padding: .22rem .32rem;
  font-size: .75rem;
}

.pane-extra .icon { width: .8rem; height: .8rem; }
.pane-extra .button:disabled { opacity: .55; }

.pane-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 0;
  color: var(--ink);
  font-size: .875rem;
  font-weight: 650;
}

.word-count, .character-summary {
  color: var(--muted);
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
}

.character-summary { justify-content: flex-start; margin: .45rem 0 .4rem; color: #287849; }
.word-count { margin: 0; }

.plan-tag {
  padding: .05rem .43rem;
  border-radius: 6px;
  background: #dff6e8;
  color: #296344;
  font-size: .7rem;
  font-weight: 600;
}

.pane-body {
  position: relative;
  display: grid;
  min-height: 0;
  flex: 1;
}

.editor-text {
  display: block;
  width: 100%;
  height: 100%;
  padding: 1.75rem 1.5rem;
  border: 0;
  border-radius: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.65;
}

.result-pane .editor-text { padding-top: 1.5rem; }
.editor-text::placeholder { color: var(--muted); opacity: 1; }
.editor-text:focus-visible { outline: 2px solid #b6aef8; outline-offset: -3px; }

.output-empty {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: .25rem;
  padding: 1rem;
  color: var(--muted);
  text-align: center;
}

.empty-mark { margin-bottom: .3rem; }
.empty-mark .icon { width: 1.4rem; height: 1.4rem; }
.empty-title, .empty-caption { margin: 0; font-size: .875rem; }

.editor-actions { margin-top: 16px; }
.result-actions { margin-top: auto; padding-top: 16px; }

.model-control {
  display: flex;
  align-items: center;
  gap: .55rem;
}

.model-control label {
  color: var(--ink);
  font-size: .875rem;
  font-weight: 550;
  white-space: nowrap;
}

#tone-select {
  min-width: 0;
  min-height: 33px;
  flex: 1;
  padding: .32rem 1.85rem .32rem .65rem;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--page);
  background-image: linear-gradient(45deg, transparent 49%, #666 50%, #666 66%, transparent 67%), linear-gradient(-45deg, transparent 49%, #666 50%, #666 66%, transparent 67%);
  background-position: right 13px center, right 8px center;
  background-repeat: no-repeat;
  background-size: 5px 5px;
  color: var(--ink);
  cursor: pointer;
}

#tone-select:hover { background-color: #f7f7f7; }

.limit-note {
  margin: .4rem 0 .45rem;
  color: var(--muted);
  font-size: .78rem;
}

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

.action-row + .action-row { margin-top: .5rem; }

.action-row .button {
  justify-self: stretch;
  border-color: var(--line);
  background: var(--page);
}

.action-row .button:hover:not(:disabled) { background: #f5f5f5; }
.action-row .button:disabled { color: #737373; background: #fafafa; }

.action-row .button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.action-row .button-primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.action-row .button-primary:disabled {
  border-color: #a69af4;
  background: #a69af4;
  color: #fff;
}

.editor-footer { margin-top: .5rem; }
.editor-footer:has(#editor-status:empty) { display: none; }
.editor-feedback { color: var(--muted); font-size: .825rem; }
#editor-status { margin: 0; }

textarea[aria-invalid='true'] { box-shadow: inset 0 0 0 1px #a12214; }
[data-error='true'] { color: #a12214; }

.workspace-note {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin: .65rem 0 0;
  color: var(--muted);
  font-size: .775rem;
}

.workspace-note .icon { width: .85rem; height: .85rem; }

.drafts-dialog {
  width: min(100% - 2rem, 510px);
  max-height: min(80vh, 680px);
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--page);
  color: var(--ink);
  box-shadow: 0 18px 48px #0003;
}

.drafts-dialog::backdrop { background: #0006; }
.info-dialog { overflow: auto; }
.info-dialog::backdrop { background: #0002; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.dialog-header :is(h2, h3) { margin: 0; font-size: 1.15rem; }
.dialog-header p { margin: .3rem 0 0; color: var(--muted); font-size: .875rem; }
.draft-tools { display: flex; flex-wrap: wrap; gap: .25rem; margin-block: .65rem; }
.draft-tools .button { border-color: var(--line); }
.draft-tools .button:disabled { opacity: .6; }
.drafts-list { display: grid; gap: .5rem; margin-top: .8rem; }
.drafts-list p { margin: .5rem 0; color: var(--muted); }

.draft-entry {
  display: grid;
  gap: .1rem;
  padding: .7rem .85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  overflow-wrap: anywhere;
}

.draft-entry:hover { border-color: #cbc7f7; background: #f6f4ff; }
.draft-entry time { color: var(--muted); font-size: .813rem; }

@media (max-width: 1100px) {
  .app-shell { --sidebar-width: 214px; }
  .usage-card { grid-template-columns: minmax(max-content, 1fr) minmax(120px, 40%) minmax(max-content, 1fr); }
  .workspace { padding: 18px; }
  .editor-grid { gap: 12px; }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .site-header { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .site-header-inner { display: grid; align-items: center; }
  .sidebar-top,
  .sidebar-collapsed .sidebar-top {
    min-height: 56px;
    flex-direction: row;
    justify-content: space-between;
    padding: .45rem .95rem;
  }
  .sidebar-group { margin: 0; }
  .sidebar-label, .sidebar-profile, .sidebar-bottom { display: none; }
  .header-actions { display: flex; flex-wrap: wrap; padding: 0 .65rem .4rem; }
  .header-actions .button { width: auto; min-height: 36px; padding-inline: .65rem; }
  .sidebar-collapsed :is(.sidebar-navigation, .sidebar-bottom) { display: none; }
  .sidebar-collapsed .brand-copy { display: grid; }
  .workspace { padding: 14px; }
  .usage-card { min-height: 72px; gap: .7rem; }
  .editor-grid { grid-template-columns: minmax(0, 1fr); gap: 1.1rem; }
  .editor-pane { height: 370px; }
  .pane-extra { opacity: 1; }
}

@media (max-width: 600px) {
  .usage-card {
    min-height: auto;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .6rem .45rem;
    margin-bottom: 12px;
    padding: .62rem .7rem;
  }
  .usage-summary { gap: .45rem; }
  .usage-details { grid-column: 2; grid-row: 1; }
  .usage-info { top: .45rem; right: .35rem; transform: none; }
  .usage-progress { grid-row: 2; grid-column: 1 / -1; height: 7px; }
  .editor-grid { grid-template-columns: minmax(0, 1fr); gap: 1.1rem; }
  .editor-pane { height: 320px; }
  .pane-heading { padding-inline: 1rem; }
  .editor-actions { margin-top: 10px; }
  .result-actions { padding-top: 0; }
  .editor-text { padding: 1rem; }
  .workspace-note { align-items: flex-start; }
}

@media (hover: none) {
  .pane-extra { opacity: 1; }
}

@media (max-width: 360px) {
  .workspace { padding: 10px; }
  .action-row { gap: .3rem; }
  .action-row .button { gap: .25rem; padding-inline: .25rem; font-size: .79rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; }
}
