:root {
  --ink: #171713;
  --paper: #f2f0e9;
  --panel: #fbfaf6;
  --yellow: #ffd84d;
  --orange: #ff5c35;
  --purple: #7267f0;
  --line: #c7c3b8;
  --muted: #716e66;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 23, 19, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 23, 19, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", Arial, sans-serif;
}

button, textarea { font: inherit; }
button { color: inherit; }

.shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 38px 0 28px;
}

.hero { border-top: 2px solid var(--ink); }

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
}

.brand,
.status,
.mode-tab,
.tool-bar,
.panel label,
.panel-label,
.panel-footer,
.composer-meta,
.composer-hint,
footer {
  font-family: Consolas, "Courier New", monospace;
  letter-spacing: 0.07em;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 28px;
  place-items: center;
  color: var(--paper);
  background: var(--ink);
  font-size: 11px;
  letter-spacing: -0.04em;
}

.status {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #28ad60;
  box-shadow: 0 0 0 4px rgba(40, 173, 96, 0.12);
}

.workspace {
  margin-top: 30px;
  border: 2px solid var(--ink);
  background: var(--panel);
  box-shadow: 9px 9px 0 var(--ink);
}

.status.offline .status-dot {
  background: #b67832;
  box-shadow: 0 0 0 4px rgba(182, 120, 50, 0.12);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 2px solid var(--ink);
}

.mode-tab {
  position: relative;
  border: 0;
  padding: 18px 22px;
  background: #dedbd2;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  transition: background 140ms ease;
}

.mode-tab + .mode-tab { border-left: 2px solid var(--ink); }
.mode-tab:hover { background: #e9e6de; }
.mode-tab.active { background: var(--yellow); }
.mode-tab.active::after {
  position: absolute;
  right: 20px;
  bottom: -8px;
  width: 14px;
  height: 14px;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  background: var(--yellow);
  content: "";
  transform: rotate(45deg);
}

.tab-number { margin-right: 12px; color: rgba(23, 23, 19, 0.5); font-size: 10px; }
.tool-view[hidden] { display: none; }

.tool-bar {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 2px solid var(--ink);
  font-size: 12px;
}


.model-badge {
  padding: 7px 10px;
  background: var(--yellow);
  font-size: 10px;
  font-weight: 700;
}

.model-badge.qwen { color: white; background: var(--purple); }
.model-badge.open-chat { color: white; background: #b33c78; }
.model-picker { margin-left: 18px; }
.model-select {
  max-width: 260px;
  border: 1px solid var(--ink);
  padding: 7px 10px;
  color: white;
  background: var(--purple);
  cursor: pointer;
  font: 700 10px Consolas, "Courier New", monospace;
  letter-spacing: 0.04em;
}
.model-select:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.model-select:disabled { cursor: wait; opacity: 0.65; }
.model-select option { color: var(--ink); background: white; }
.tool-kicker { margin-right: 12px; font-weight: 700; }
.tool-description { color: var(--muted); letter-spacing: 0; }

.translation-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  height: max(200px, calc(100vh - 370px));
  height: max(200px, calc(100dvh - 370px));
  min-height: 0;
}

.panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  padding: 24px;
}

.input-panel { border-right: 2px solid var(--ink); }

.panel label,
.panel-label {
  flex-shrink: 0;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

textarea,
.result {
  width: 100%;
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: clamp(18px, 2vw, 24px);
  line-height: 1.68;
  resize: none;
}

.translation-panels textarea,
.translation-panels .result {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  font-size: 15px;
  line-height: 1.72;
}

textarea::placeholder,
.result.empty { color: #aaa69d; }
.result {
  min-height: 0;
  overflow-y: auto;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.result.waiting::after,
.vision-result.waiting::after,
.typing-bubble::after {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 9px;
  border-radius: 50%;
  background: var(--orange);
  animation: pulse 0.8s infinite alternate;
  content: "";
}

.panel-footer {
  display: flex;
  flex-shrink: 0;
  min-height: 30px;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  color: var(--muted);
  font-size: 10px;
}

.output-footer { justify-content: flex-end; gap: 14px; }

.text-button {
  border: 0;
  border-bottom: 1px solid currentColor;
  padding: 2px 0;
  background: transparent;
  cursor: pointer;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
}

.text-button:disabled { opacity: 0.3; cursor: default; }

.error-message {
  margin: 0 22px 20px;
  border-left: 4px solid var(--orange);
  padding: 11px 14px;
  color: #8d2412;
  background: #ffe7df;
  font-size: 14px;
}

.translation-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.translation-actions .action-button + .action-button { border-left: 2px solid var(--ink); }

.action-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 18px;
  border: 0;
  border-top: 2px solid var(--ink);
  padding: 20px;
  background: var(--yellow);
  cursor: pointer;
  font-size: 16px;
  font-weight: 900;
  transition: background 140ms ease, color 140ms ease;
}

.action-button:hover:not(:disabled) { color: white; background: var(--orange); }
.action-button:disabled, .send-button:disabled { cursor: wait; opacity: 0.75; }

.shortcut {
  border: 1px solid currentColor;
  padding: 3px 6px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  font-weight: 400;
}

.loading .button-label::after,
.loading .send-label::after {
  display: inline-block;
  width: 0;
  overflow: hidden;
  vertical-align: bottom;
  animation: dots 1.2s steps(4, end) infinite;
  content: "...";
}

.chat-view .tool-bar { background: #f0eee8; }
.open-chat-view .tool-bar { background: #f4e9ef; }
.open-chat-view .chat-log {
  background:
    radial-gradient(circle at 80% 20%, rgba(179, 60, 120, 0.07), transparent 24%),
    var(--panel);
}
.open-chat-view .message.assistant .message-content { border-left-color: #b33c78; }
.spark.open { color: #b33c78; }
.send-button.open-send { background: #b33c78; }

.chat-log {
  height: max(410px, calc(100vh - 454px));
  height: max(410px, calc(100dvh - 454px));
  min-height: 410px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  padding: 34px 7%;
  background:
    radial-gradient(circle at 80% 20%, rgba(114, 103, 240, 0.06), transparent 24%),
    var(--panel);
}

.chat-empty {
  display: flex;
  min-height: 100%;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.spark { color: var(--purple); font-size: 30px; }
.chat-empty h2 { margin: 12px 0 8px; font-size: 28px; letter-spacing: -0.04em; }
.chat-empty p { margin: 0; color: var(--muted); font-size: 14px; }

.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 28px; }
.suggestions button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  transition: border-color 140ms ease, background 140ms ease;
}
.suggestions button:hover { border-color: var(--purple); background: rgba(114, 103, 240, 0.07); }

.message { display: flex; margin-bottom: 26px; }
.message.user { justify-content: flex-end; }
.message-inner { min-width: 0; max-width: min(78%, 760px); }
.message-meta {
  margin-bottom: 7px;
  color: var(--muted);
  font: 10px Consolas, "Courier New", monospace;
  letter-spacing: 0.08em;
}
.message.user .message-meta { text-align: right; }
.message-content {
  border: 1px solid var(--line);
  padding: 15px 17px;
  background: white;
  font-size: 15px;
  line-height: 1.72;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message.user .message-content { border-color: var(--ink); background: var(--ink); color: white; }
.message.assistant .message-content { border-left: 4px solid var(--purple); }
.message-copy { margin-top: 7px; border-color: var(--muted); color: var(--muted); }
.typing-bubble { color: var(--muted); }

.chat-error { margin-top: 18px; }

.chat-composer {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border-top: 2px solid var(--ink);
  background: white;
}

.chat-composer textarea {
  min-height: 126px;
  padding: 22px 86px 44px 22px;
  font-size: 17px;
  line-height: 1.5;
}

.composer-meta {
  position: absolute;
  right: 88px;
  bottom: 15px;
  left: 22px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
}

.send-button {
  display: flex;
  width: 74px;
  align-items: center;
  align-self: stretch;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-left: 2px solid var(--ink);
  background: var(--purple);
  color: white;
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
}
.send-label { font-size: 11px; }

.composer-hint {
  margin: 0;
  padding: 10px 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: #f0eee8;
  font-size: 9px;
  text-align: center;
}

.model-badge.vision {
  color: white;
  background: var(--orange);
}

.vision-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  grid-template-rows: minmax(0, 1fr);
  height: max(410px, calc(100vh - 416px));
  height: max(410px, calc(100dvh - 416px));
  min-height: 410px;
}

.vision-upload-column {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 24px;
  border-right: 2px solid var(--ink);
}

.drop-zone {
  display: flex;
  width: 100%;
  min-height: 340px;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  border: 2px dashed var(--line);
  padding: 28px;
  background: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--orange);
  background: rgba(255, 92, 53, 0.06);
}

.drop-zone.dragging { transform: scale(0.99); }
.drop-zone strong { margin: 17px 0 7px; font-size: 17px; }
.drop-zone > span:not(.upload-icon) { color: var(--muted); font-size: 13px; }
.drop-zone small { margin-top: 22px; color: var(--muted); font: 10px Consolas, "Courier New", monospace; }

.upload-icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 2px solid var(--ink);
  background: var(--yellow);
  font-size: 29px;
  line-height: 1;
}

.image-preview-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  min-height: 0;
}

.image-preview-wrap img {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  height: 0;
  border: 1px solid var(--line);
  background: #e9e6de;
  object-fit: contain;
}

.preview-meta {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  color: var(--muted);
  font: 10px Consolas, "Courier New", monospace;
}

.preview-meta > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vision-result-column {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
  padding: 24px;
}

.vision-result-header {
  display: flex;
  flex-shrink: 0;
  align-items: flex-start;
  justify-content: space-between;
}

.vision-result {
  flex: 1;
  min-height: 0;
  font-size: 15px;
  line-height: 1.75;
  overflow-wrap: anywhere;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  white-space: pre-wrap;
}

.vision-result.empty {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.vision-placeholder-icon { color: var(--orange); font-size: 34px; }
.vision-result.empty p { margin: 12px 0 0; }

.vision-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border-top: 2px solid var(--ink);
  background: white;
}

.vision-composer textarea {
  min-height: 108px;
  padding: 20px 22px;
  font-size: 16px;
  line-height: 1.5;
}

.vision-action {
  display: flex;
  min-width: 190px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 0;
  border-left: 2px solid var(--ink);
  padding: 18px;
  color: white;
  background: var(--orange);
  cursor: pointer;
  font-weight: 800;
}

.vision-action:hover:not(:disabled) { background: var(--ink); }
.vision-action:disabled { cursor: wait; opacity: 0.72; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

footer {
  display: flex;
  justify-content: space-between;
  margin-top: 30px;
  color: var(--muted);
  font-size: 10px;
}

@keyframes pulse { to { opacity: 0.15; } }
@keyframes dots { to { width: 1.5em; } }

@media (max-width: 720px) {
  .translation-actions .action-button { gap: 8px; padding: 20px 8px; font-size: 14px; }
  .translation-actions .shortcut { display: none; }
  .shell { width: min(100% - 24px, 1180px); padding-top: 20px; }
  .mode-tab { padding: 16px 14px; font-size: 12px; }
  .tab-number { display: none; }
  .translation-panels {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(2, minmax(0, 1fr));
    height: max(180px, calc(100vh - 365px));
    height: max(180px, calc(100dvh - 365px));
  }
  .translation-panels .panel { padding: 12px; }
  .translation-panels .panel-label,
  .translation-panels label { margin-bottom: 10px; }
  .translation-panels .panel-footer { min-height: 20px; margin-top: 8px; }
  .input-panel { border-right: 0; border-bottom: 2px solid var(--ink); }
  .model-badge { display: none; }
  .model-picker { max-width: 52%; }
  .model-select { width: 100%; }
  .tool-description { display: none; }
  .chat-log {
    height: max(380px, calc(100vh - 398px));
    height: max(380px, calc(100dvh - 398px));
    min-height: 380px;
    padding: 28px 18px;
  }
  .message-inner { max-width: 90%; }
  .suggestions { align-items: center; flex-direction: column; }
  .composer-hint { display: none; }
  .vision-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 260px clamp(300px, 50dvh, 480px);
    height: auto;
    min-height: 0;
  }
  .vision-upload-column { border-right: 0; border-bottom: 2px solid var(--ink); }
  .vision-result-column { min-height: 0; }
  .vision-composer { grid-template-columns: 1fr; }
  .vision-action { min-height: 62px; border-top: 2px solid var(--ink); border-left: 0; }
  footer { gap: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; animation-duration: 0.01ms !important; }
}
