:root {
  --paper: #FAF8F5;
  --paper-warm: #F5F0EA;
  --surface: #FFFFFF;
  --ink: #2C2824;
  --ink-light: #6B6460;
  --ink-faint: #A8A09A;
  --ink-ghost: #D4CFC9;
  --blush: #D4736E;
  --blush-soft: #F5E1DF;
  --indigo: #5B6DAF;
  --indigo-soft: #E4E8F4;
  --sage: #7A9A82;
  --sage-soft: #E4EDE6;
  --gold: #C4A265;
  --gold-soft: #F0E8D4;
  --warm-brown: #8B7162;
  --soft-brown: #A68E7E;
  --border: #E8E2DB;
  --radius: 4px;
  --btn-text: #FFF8F4;
  --noise-opacity: 0.025;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #1A1816;
    --paper-warm: #23201D;
    --surface: #2A2724;
    --ink: #F0ECE8;
    --ink-light: #CCC5BC;
    --ink-faint: #968E86;
    --ink-ghost: #6B6360;
    --blush: #E08B86;
    --blush-soft: #3A2625;
    --indigo: #8090C8;
    --indigo-soft: #282D40;
    --sage: #92B89A;
    --sage-soft: #222E25;
    --gold: #D4B275;
    --gold-soft: #332D1E;
    --warm-brown: #B89A8A;
    --soft-brown: #C4A898;
    --border: #3A3530;
    --btn-text: #FFF8F4;
    --noise-opacity: 0.04;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Subtle noise texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  opacity: var(--noise-opacity);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink-ghost); border-radius: 4px; }

@keyframes enter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideReveal {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes breathe {
  0%,100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.app {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

/* === Header === */
.header {
  padding: 64px 0 48px;
  text-align: center;
  animation: enter 0.7s ease-out;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}
.header-jp {
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-faint);
  letter-spacing: 6px;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.header h1 {
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 48px;
  font-weight: 700;
  color: var(--warm-brown);
  letter-spacing: -1px;
  line-height: 1.1;
}
.header-line {
  width: 32px;
  height: 1px;
  background: var(--ink-ghost);
  margin: 20px auto;
}
.header-desc {
  font-size: 13px;
  color: var(--ink-light);
  font-weight: 300;
  line-height: 1.7;
}

/* === Section === */
.section {
  margin-bottom: 36px;
  animation: enter 0.6s ease-out both;
}
.section:nth-child(2) { animation-delay: 0.05s; }
.section:nth-child(3) { animation-delay: 0.1s; }
.section:nth-child(4) { animation-delay: 0.15s; }
.section:nth-child(5) { animation-delay: 0.2s; }

.section-label {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}
.section-label .num {
  font-family: 'Klee One', cursive;
  font-size: 28px;
  font-weight: 400;
  color: var(--ink-ghost);
  line-height: 1;
}
.section-label .title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-light);
}
.section-label .sub {
  font-size: 11px;
  color: var(--ink-faint);
  margin-left: auto;
  font-weight: 300;
}

/* === API Key === */
.key-field {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  transition: border-color 0.2s;
}
.key-field:focus-within { border-color: var(--ink-faint); }
.key-prefix {
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--ink-faint);
  background: var(--paper-warm);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
.key-input {
  flex: 1;
  padding: 12px 14px;
  border: none;
  background: transparent;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--ink);
  outline: none;
}
.key-input::placeholder { color: var(--ink-ghost); }

/* === Upload === */
.upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  background: transparent;
}
.upload-zone:hover {
  border-color: var(--ink-faint);
  background: var(--paper-warm);
}
.upload-zone .ux-icon {
  font-size: 32px;
  margin-bottom: 12px;
  opacity: 0.6;
}
.upload-zone .ux-text {
  font-size: 13px;
  color: var(--ink-light);
  font-weight: 400;
}
.upload-zone .ux-hint {
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 6px;
  font-weight: 300;
}
.upload-zone.filled {
  border-style: solid;
  border-color: var(--sage);
  padding: 8px;
  background: var(--surface);
}
.img-wrap { position: relative; }
.img-wrap img {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  display: block;
  border-radius: 2px;
  background: var(--paper-warm);
}
.img-del {
  position: absolute;
  top: 8px; right: 8px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-light);
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.img-del:hover { background: var(--blush); color: white; border-color: var(--blush); }

/* === Textarea === */
.text-field-wrap {
  position: relative;
}
.text-field {
  width: 100%;
  min-height: 140px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 14px;
  font-weight: 300;
  line-height: 2;
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
.text-field:focus { border-color: var(--ink-faint); }
.text-field::placeholder { color: var(--ink-ghost); }
.text-field-lines {
  position: absolute;
  top: 16px;
  left: 18px;
  right: 18px;
  bottom: 16px;
  pointer-events: none;
  background: repeating-linear-gradient(
    transparent,
    transparent 27px,
    var(--border) 27px,
    var(--border) 28px
  );
  border-radius: 2px;
}
.text-meta {
  display: flex;
  justify-content: flex-end;
  font-size: 10px;
  color: var(--ink-ghost);
  margin-top: 6px;
  font-family: 'IBM Plex Mono', monospace;
}

/* === Button === */
.action-btn {
  width: 100%;
  padding: 16px;
  border: 1.5px solid var(--warm-brown);
  border-radius: var(--radius);
  background: var(--warm-brown);
  color: var(--btn-text);
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: 1px;
  animation: enter 0.6s ease-out both;
  animation-delay: 0.25s;
}
.action-btn:hover:not(:disabled) {
  background: var(--soft-brown);
  border-color: var(--soft-brown);
  color: var(--btn-text);
}
.action-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}
.action-btn .arrow {
  font-size: 18px;
  transition: transform 0.2s;
}
.action-btn:hover:not(:disabled) .arrow { transform: translateX(4px); }

/* === Loading === */
.loading-box {
  text-align: center;
  padding: 32px;
  animation: fadeIn 0.4s;
}
.loading-bar {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 14px;
}
.loading-bar span {
  width: 3px; height: 16px;
  background: var(--ink-ghost);
  animation: breathe 1.2s ease-in-out infinite;
  border-radius: 1px;
}
.loading-bar span:nth-child(2) { animation-delay: 0.15s; height: 22px; }
.loading-bar span:nth-child(3) { animation-delay: 0.3s; height: 12px; }
.loading-bar span:nth-child(4) { animation-delay: 0.45s; height: 20px; }
.loading-bar span:nth-child(5) { animation-delay: 0.6s; height: 14px; }
.loading-label {
  font-size: 12px;
  color: var(--ink-faint);
  font-weight: 300;
  letter-spacing: 2px;
}

/* === Result Page === */
.back-link {
  display: inline-block;
  margin-top: 32px;
  font-size: 13px;
  color: var(--ink-faint);
  text-decoration: none;
  font-weight: 400;
  transition: color 0.2s;
}
.back-link:hover { color: var(--ink); }

.result-header {
  padding: 32px 0 28px;
  text-align: center;
  animation: enter 0.7s ease-out;
  border-bottom: 1px solid var(--border);
  margin-bottom: 36px;
}
.result-header-jp {
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 6px;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.result-header h1 {
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.5px;
}

.back-btn {
  display: flex;
  text-decoration: none;
  margin-top: 40px;
}

/* --- Sentence Card --- */
.sentence-card {
  margin-bottom: 32px;
  animation: enter 0.5s ease-out both;
}
.sentence-num {
  font-family: 'Klee One', cursive;
  font-size: 32px;
  color: var(--ink-ghost);
  margin-bottom: 12px;
  line-height: 1;
}

.correction-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 12px;
}
.area-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.area-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.area-dot--grammar { background: var(--indigo); }
.area-dot--natural { background: var(--sage); }

/* --- Sentence Rows --- */
.sentence-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
}
.sentence-row + .sentence-row {
  border-top: 1px solid var(--border);
}
.row-tag {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--indigo-soft);
  color: var(--indigo);
  font-family: 'Noto Sans KR', sans-serif;
}
.row-tag--fix {
  background: var(--blush-soft);
  color: var(--blush);
}
.row-tag--natural {
  background: var(--sage-soft);
  color: var(--sage);
}
.row-text {
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink);
}
.sentence-row--original .row-text {
  color: var(--ink-light);
}

/* --- Highlight --- */
.hl {
  font-weight: 600;
  padding: 1px 2px;
  border-radius: 2px;
}
.hl--fix {
  color: var(--blush);
  background: var(--blush-soft);
}
.hl--natural {
  color: var(--sage);
  background: var(--sage-soft);
}

/* --- Note/Explanation --- */
.sentence-note {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--paper-warm);
  border-radius: var(--radius);
  font-size: 12.5px;
  line-height: 1.9;
  color: var(--ink-light);
  font-weight: 300;
  white-space: pre-wrap;
}

/* === Error === */
.error-msg {
  margin-top: 16px;
  padding: 14px 18px;
  border-left: 3px solid var(--blush);
  background: var(--blush-soft);
  font-size: 13px;
  color: var(--blush);
  animation: fadeIn 0.3s;
}

.footer {
  text-align: center;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-family: 'Klee One', cursive;
  font-size: 13px;
  color: var(--ink-ghost);
  letter-spacing: 2px;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
  padding: 24px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  animation: enter 0.3s ease-out;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}
.modal-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--gold);
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}
.modal-title {
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 20px;
}
.modal-body {
  text-align: left;
  margin-bottom: 24px;
}
.modal-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--ink-light);
  line-height: 1.6;
}
.modal-item + .modal-item {
  border-top: 1px solid var(--border);
}
.modal-bullet {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--blush-soft);
  color: var(--blush);
  font-family: 'Klee One', cursive;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-btn {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--warm-brown);
  border-radius: var(--radius);
  background: var(--warm-brown);
  color: var(--btn-text);
  font-family: 'Zen Maru Gothic', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}
.modal-btn:hover {
  background: var(--soft-brown);
  border-color: var(--soft-brown);
}
.modal-error-text {
  font-size: 13px;
  color: var(--blush);
  line-height: 1.8;
  text-align: center;
  word-break: break-word;
}

@media (max-width: 640px) {
  .app { padding: 0 18px 60px; }
  .header { padding: 48px 0 36px; }
  .header h1 { font-size: 36px; }
}
