:root {
  color-scheme: dark;
  /* 공용 실험실 토큰(lab-experience.css)에 매핑. paper·serif 만 Tudish 고유. */
  --td-bg: var(--lab-bg);
  --td-ink: var(--lab-ink);
  --td-ink-dim: var(--lab-muted);
  --td-ink-faint: var(--lab-dim);
  --td-line: var(--lab-line);
  --td-line-strong: var(--lab-line-strong);
  --td-surface: var(--lab-surface);
  --td-surface-raised: var(--lab-surface-raised);
  --td-paper: #e9e9e6;
  --td-serif: 'Noto Serif KR', 'Noto Sans KR', serif;
  --td-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body.tudish-body {
  min-height: 100dvh;
  background:
    radial-gradient(1100px 540px at 50% -12%, rgba(255, 255, 255, 0.05), transparent 62%),
    radial-gradient(900px 480px at 88% 112%, rgba(255, 255, 255, 0.025), transparent 58%),
    var(--td-bg);
  color: var(--td-ink);
  font-family: var(--font-family), 'Noto Sans KR', sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 30;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--td-paper);
  color: #131312;
  font-size: 13px;
  font-weight: 700;
  transform: translateY(-160%);
}

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

.tudish-shell {
  display: grid;
  width: 100%;
  min-height: 100dvh;
  grid-template-rows: auto 1fr;
  overflow-x: hidden;
  padding: max(18px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

/* -- top bar ---------------------------------------------------------- */
.tudish-topbar {
  display: grid;
  min-height: 52px;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  width: min(1180px, 100%);
  justify-self: center;
}

.tudish-brand {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 10px;
}

.tudish-brand strong {
  color: #ffffff;
  font-family: 'Instrument Sans', var(--font-family), sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.tudish-brand span,
.tudish-engine-status {
  color: var(--td-ink-dim);
  font-size: 12px;
  font-weight: 600;
}

.tudish-engine-status {
  justify-self: end;
  color: var(--td-ink-faint);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

/* -- layout ------------------------------------------------------------- */
.tudish-workbench {
  display: grid;
  width: min(1180px, 100%);
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-self: stretch;
  justify-self: center;
  padding: 18px 0 8px;
}

.tudish-chat,
.tudish-side,
.tudish-panel,
.tudish-composer {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.tudish-chat {
  display: grid;
  min-height: min(760px, calc(100dvh - 118px));
  grid-template-rows: 1fr auto;
  overflow: hidden;
  border: 1px solid var(--td-line);
  border-radius: 18px;
  background: var(--td-surface);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.4);
}

.tudish-dialogue {
  display: flex;
  min-height: 360px;
  flex-direction: column;
  gap: 22px;
  overflow-y: auto;
  padding: 30px 30px 22px;
  scrollbar-width: thin;
  scrollbar-color: #3c3c3c transparent;
}

/* -- welcome ------------------------------------------------------------ */
.tudish-welcome {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 26px 10px;
  text-align: center;
  animation: tudish-rise 500ms ease both;
}

.tudish-welcome-glyph {
  margin: 0 0 4px;
  color: var(--td-ink-faint);
  font-family: var(--td-serif);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.55em;
  text-indent: 0.55em;
}

.tudish-welcome-title {
  margin: 0;
  color: #ffffff;
  font-family: var(--td-serif);
  font-size: clamp(26px, 4vw, 34px);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.tudish-welcome-sub {
  margin: 4px 0 14px;
  color: var(--td-ink-dim);
  font-size: 14px;
  line-height: 1.7;
  word-break: keep-all;
}

.tudish-welcome-chips {
  display: flex;
  max-width: 460px;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.tudish-welcome-chips button {
  padding: 11px 16px;
  border: 1px solid var(--td-line);
  border-radius: 12px;
  background: transparent;
  color: #cfcfcc;
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.tudish-welcome-chips button:hover,
.tudish-welcome-chips button:focus-visible {
  border-color: var(--td-line-strong);
  background: var(--td-surface-raised);
  color: #ffffff;
}

.tudish-welcome-chips em {
  margin-left: 6px;
  color: var(--td-ink-faint);
  font-size: 11px;
  font-style: normal;
  letter-spacing: 0.06em;
}

/* -- messages ------------------------------------------------------------- */
.tudish-message {
  display: grid;
  max-width: min(640px, 94%);
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  animation: tudish-rise 320ms ease both;
}

.tudish-message--user {
  align-self: end;
  grid-template-columns: minmax(0, 1fr) 32px;
}

.tudish-message--user .tudish-avatar {
  grid-column: 2;
  border-color: transparent;
  background: var(--td-paper);
  color: #161615;
}

.tudish-message--user .tudish-bubble {
  grid-column: 1;
  grid-row: 1;
  border-color: transparent;
  border-radius: 16px 4px 16px 16px;
  background: var(--td-paper);
  color: #171716;
}

.tudish-avatar {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--td-line);
  border-radius: 10px;
  background: var(--td-surface-raised);
  color: #dcdcda;
  font-family: 'Instrument Sans', var(--font-family), sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tudish-bubble {
  min-width: 0;
  padding: 13px 16px 12px;
  border: 1px solid var(--td-line);
  border-radius: 4px 16px 16px 16px;
  background: var(--td-surface-raised);
  color: var(--td-ink);
  line-height: 1.66;
}

.tudish-bubble .tudish-text {
  margin: 0;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.tudish-message--assistant .tudish-bubble .tudish-text {
  font-family: var(--td-serif);
  font-size: 16.5px;
  font-weight: 500;
  letter-spacing: -0.004em;
}

.tudish-message.is-streaming .tudish-text::after {
  display: inline-block;
  margin-left: 1px;
  content: "▍";
  color: var(--td-ink-dim);
  animation: tudish-blink 860ms steps(1) infinite;
}

.tudish-message.is-thinking .tudish-text::after {
  display: inline-block;
  width: 1.3em;
  content: "";
  color: var(--td-ink-dim);
  animation: tudish-dots 1s steps(3, end) infinite;
}

.tudish-msg-ipa {
  margin: 8px 0 0;
  color: var(--td-ink-faint);
  font-family: var(--td-mono);
  font-size: 11.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.tudish-msg-meta {
  display: block;
  margin-top: 7px;
  color: var(--td-ink-faint);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.tudish-msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid var(--td-line);
}

.tudish-msg-actions button {
  padding: 5px 11px;
  border: 1px solid var(--td-line);
  border-radius: 999px;
  background: transparent;
  color: var(--td-ink-dim);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
}

.tudish-msg-actions button:hover:not(:disabled),
.tudish-msg-actions button:focus-visible {
  border-color: var(--td-line-strong);
  background: var(--td-surface-raised);
  color: #ffffff;
}

.tudish-msg-actions button:disabled {
  cursor: default;
  opacity: 0.4;
}

/* -- composer ----------------------------------------------------------- */
.tudish-composer {
  display: grid;
  gap: 9px;
  padding: 13px 16px 15px;
  border-top: 1px solid var(--td-line);
  background: rgba(10, 10, 11, 0.72);
  backdrop-filter: blur(10px);
}

.tudish-composer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tudish-direction-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px 6px 10px;
  border: 1px solid var(--td-line);
  border-radius: 999px;
  background: transparent;
  color: var(--td-ink-dim);
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
}

.tudish-direction-pill .material-symbols-outlined {
  font-size: 16px;
  transition: transform 240ms ease;
}

.tudish-direction-pill:hover,
.tudish-direction-pill:focus-visible {
  border-color: var(--td-line-strong);
  background: var(--td-surface-raised);
  color: #ffffff;
}

.tudish-direction-pill:hover .material-symbols-outlined {
  transform: rotate(180deg);
}

.tudish-composer-hint {
  color: var(--td-ink-faint);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.tudish-input-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tudish-inputrow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 8px;
}

.tudish-composer textarea {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--td-line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.03);
  color: #ffffff;
  font: inherit;
  font-size: 15px;
  line-height: 1.55;
  outline: none;
  padding: 12px 15px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.tudish-composer textarea::placeholder {
  color: var(--td-ink-faint);
}

.tudish-composer textarea:focus {
  border-color: var(--td-line-strong);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.tudish-icon-button,
.tudish-submit {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--td-line);
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.tudish-icon-button {
  width: 44px;
  height: 44px;
  background: transparent;
  color: var(--td-ink-dim);
}

.tudish-icon-button--small {
  width: 30px;
  height: 30px;
  border-radius: 9px;
}

.tudish-icon-button .material-symbols-outlined,
.tudish-submit .material-symbols-outlined {
  font-size: 20px;
}

.tudish-submit {
  width: 44px;
  height: 44px;
  border-color: transparent;
  background: var(--td-paper);
  color: #131312;
}

.tudish-icon-button:hover,
.tudish-icon-button:focus-visible {
  border-color: var(--td-line-strong);
  background: var(--td-surface-raised);
  color: #ffffff;
}

.tudish-submit:hover,
.tudish-submit:focus-visible {
  background: #ffffff;
  transform: translateY(-1px);
}

.tudish-icon-button:focus-visible,
.tudish-submit:focus-visible,
.tudish-segmented button:focus-visible,
.tudish-welcome-chips button:focus-visible,
.tudish-msg-actions button:focus-visible,
.tudish-direction-pill:focus-visible,
.tudish-toggle:focus-within {
  outline: 2px solid #d9d9d9;
  outline-offset: 2px;
}

/* -- side panels ------------------------------------------------------------ */
.tudish-side {
  display: flex;
  min-height: min(760px, calc(100dvh - 118px));
  flex-direction: column;
  gap: 14px;
}

.tudish-panel {
  border: 1px solid var(--td-line);
  border-radius: 16px;
  background: var(--td-surface);
  padding: 18px;
}

.tudish-panel--preview {
  display: flex;
  min-height: 180px;
  flex-direction: column;
}

.tudish-panel--note p {
  margin: 0;
  color: var(--td-ink-faint);
  font-size: 12px;
  line-height: 1.7;
  word-break: keep-all;
}

.tudish-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 13px;
}

.tudish-section-head h2 {
  margin: 0;
  color: var(--td-ink-dim);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

.tudish-control-label {
  display: block;
  margin: 15px 0 7px;
  color: var(--td-ink-faint);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.tudish-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--td-line);
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.25);
}

.tudish-segmented--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tudish-segmented button {
  min-width: 0;
  min-height: 31px;
  padding: 0 8px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--td-ink-dim);
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease;
}

.tudish-segmented button.is-active {
  background: var(--td-paper);
  color: #131312;
}

.tudish-segmented button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.tudish-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 15px;
  color: #cfcfcc;
  font-size: 13px;
  font-weight: 600;
}

.tudish-toggle input {
  width: 38px;
  height: 20px;
  margin: 0;
  accent-color: #e9e9e6;
}

.tudish-preview-output {
  min-height: 72px;
  flex: 1;
  color: #ffffff;
  font-family: var(--td-serif);
  font-size: 17.5px;
  font-weight: 500;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.tudish-preview-output.is-empty {
  color: var(--td-ink-faint);
  font-family: var(--font-family), 'Noto Sans KR', sans-serif;
  font-size: 13.5px;
}

.tudish-preview-meta,
.tudish-ipa {
  margin: 10px 0 0;
  color: var(--td-ink-faint);
  font-size: 11.5px;
  line-height: 1.5;
}

.tudish-ipa {
  font-family: var(--td-mono);
  overflow-wrap: anywhere;
}

/* -- toast ------------------------------------------------------------------ */
.tudish-toast {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100vw - 36px);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--td-paper);
  color: #131312;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.4);
  animation: tudish-rise 220ms ease both;
}

/* -- keyframes ------------------------------------------------------------- */
@keyframes tudish-rise {
  from {
    opacity: 0;
    transform: translateY(7px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes tudish-blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

@keyframes tudish-dots {
  0% {
    content: "";
  }

  33% {
    content: "·";
  }

  66% {
    content: "· ·";
  }

  100% {
    content: "· · ·";
  }
}

@media (prefers-reduced-motion: reduce) {

  .tudish-icon-button,
  .tudish-submit,
  .tudish-direction-pill .material-symbols-outlined {
    transition: none;
  }

  .tudish-message,
  .tudish-welcome,
  .tudish-toast {
    animation: none;
  }

  .tudish-message.is-thinking .tudish-text::after,
  .tudish-message.is-streaming .tudish-text::after {
    animation: none;
  }
}

/* -- responsive -------------------------------------------------------------- */
@media (max-width: 960px) {
  .tudish-shell {
    min-height: auto;
  }

  .tudish-workbench {
    grid-template-columns: 1fr;
    align-self: start;
  }

  .tudish-chat {
    min-height: min(640px, calc(100dvh - 150px));
  }

  .tudish-side {
    display: grid;
    min-height: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tudish-panel--note {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .tudish-shell {
    padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }

  .tudish-topbar {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .tudish-engine-status {
    display: none;
  }

  .tudish-workbench {
    gap: 12px;
    padding-top: 12px;
  }

  .tudish-chat {
    min-height: min(560px, calc(100dvh - 130px));
  }

  .tudish-dialogue {
    min-height: 300px;
    gap: 18px;
    padding: 18px 16px 14px;
  }

  .tudish-message {
    max-width: 100%;
  }

  .tudish-composer {
    padding: 11px 12px 13px;
  }

  .tudish-composer-hint {
    display: none;
  }

  .tudish-welcome-sub br {
    display: none;
  }

  .tudish-segmented button {
    padding: 0 6px;
    font-size: 12px;
  }

  .tudish-side {
    grid-template-columns: 1fr;
  }
}
