:root {
  --gap: 1px;
  --jyut-size: 12px;
  --han-size: 26px;
  --bg: #f6f2eb;
  --card: rgba(255, 255, 255, 0.9);
  --ink: #20262d;
  --muted: #6f767d;
  --line: #e4d8c8;
  --accent: #7b5a3d;
  --accent-dark: #5c412b;
  --soft: #fbf3e8;
  --ok: #42705b;
  --danger: #aa6a25;
  --jyut-color: #496277;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", Arial, sans-serif;
  background:
    radial-gradient(circle at 12% 0%, rgba(229, 198, 148, 0.38), transparent 34%),
    radial-gradient(circle at 90% 92%, rgba(123, 90, 61, 0.12), transparent 28%),
    var(--bg);
}

.app-shell {
  width: min(1100px, calc(100% - 28px));
  margin: 26px auto 46px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 28px;
  border-radius: 28px;
  background: linear-gradient(135deg, #fffdf7, #f4e2c8);
  box-shadow: 0 20px 58px rgba(72, 54, 37, 0.11);
  border: 1px solid rgba(123, 90, 61, 0.16);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 750;
  letter-spacing: 0.13em;
}

.eyebrow.mini {
  font-size: 12px;
  margin-bottom: 4px;
}

h1 {
  margin: 0;
  font-size: clamp(36px, 7vw, 72px);
  line-height: 1.02;
  letter-spacing: -0.05em;
}

.sub {
  max-width: 720px;
  margin: 16px 0 0;
  color: #5f4f41;
  font-size: 18px;
  line-height: 1.65;
}

.badge {
  flex: 0 0 auto;
  width: 126px;
  height: 126px;
  border-radius: 31px;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 850;
  color: white;
  background: linear-gradient(145deg, var(--accent), #b88a55);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.42), 0 18px 38px rgba(92, 65, 43, 0.2);
}

.badge span {
  font-size: 14px;
  font-weight: 650;
  opacity: 0.9;
}

.panel {
  margin-top: 18px;
  padding: 22px;
  border-radius: 24px;
  background: var(--card);
  border: 1px solid rgba(123, 90, 61, 0.14);
  box-shadow: 0 16px 42px rgba(72, 54, 37, 0.075);
  backdrop-filter: blur(12px);
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}

h2 {
  margin: 0;
  font-size: 20px;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  padding: 18px;
  border-radius: 18px;
  border: 1.5px solid var(--line);
  outline: none;
  font-size: 20px;
  line-height: 1.75;
  background: #fffefb;
  color: var(--ink);
}

textarea:focus {
  border-color: #b58a55;
  box-shadow: 0 0 0 4px rgba(181, 138, 85, 0.16);
}

.toolbar, .copy-actions, .reader-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.copy-actions, .reader-actions { margin-top: 0; }

button {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  font-weight: 760;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease, background .12s ease;
}

button:active { transform: scale(0.98); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.main-btn {
  padding: 13px 20px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 12px 28px rgba(123, 90, 61, 0.22);
}
.main-btn:hover { background: var(--accent-dark); }

.soft-btn, .ghost-btn {
  padding: 12px 18px;
  color: var(--accent-dark);
  background: var(--soft);
  border: 1px solid rgba(123, 90, 61, 0.14);
}

.ghost-btn { background: #fff; }
.small { padding: 10px 15px; font-size: 14px; }

.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 680;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.settings-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 740;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }

.tiny-tip {
  margin: 12px 0 0;
  color: #75808a;
  font-size: 14px;
  line-height: 1.55;
}

.status {
  min-height: 28px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 680;
}

.status.ok { color: var(--ok); }
.status.warn { color: var(--danger); }

.output-wrap {
  position: relative;
}

.annotated-output {
  min-height: 230px;
  padding: 22px 56px 22px 22px;
  border: 1.5px dashed #d6c0a3;
  border-radius: 20px;
  background: #fffefb;
  line-height: 2.02;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.token {
  display: inline-grid;
  grid-template-rows: auto auto;
  justify-items: center;
  align-items: end;
  width: max-content;
  min-width: calc(var(--han-size) + 2px);
  margin: 3px calc(var(--gap) * 0.55) 5px 0;
  padding: 0 2px;
  overflow: visible;
  vertical-align: bottom;
}

.jp {
  min-height: calc(var(--jyut-size) + 3px);
  font-size: var(--jyut-size);
  line-height: 1.05;
  color: var(--jyut-color);
  font-family: "Avenir Next", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  font-weight: 520;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border-radius: 6px;
  padding: 0 2px;
  outline: none;
  text-align: center;
  max-width: 8.8ch;
  overflow: hidden;
  text-overflow: clip;
}

.jp:focus {
  background: #eef5fa;
  box-shadow: 0 0 0 2px #d6e4ee;
}

.han {
  font-size: var(--han-size);
  line-height: 1.18;
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "PingFang SC", "Noto Serif CJK SC", serif;
  color: #25282c;
}

.punct {
  display: inline-block;
  margin: 0 2px 3px 0;
  font-size: var(--han-size);
  color: #464039;
  vertical-align: bottom;
}

.space-token {
  display: inline-block;
  width: 7px;
}

.line-break {
  display: block;
  height: 8px;
}

.unknown .jp {
  color: #aa6a25;
}

.muted-empty {
  color: #9aa1a8;
  font-size: 18px;
}

.zoom-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: rgba(92, 65, 43, 0.82);
  box-shadow: 0 12px 28px rgba(72, 54, 37, 0.18);
  font-size: 25px;
  font-family: Georgia, serif;
}

.zoom-btn:hover {
  background: rgba(92, 65, 43, 0.96);
}

.help-panel p {
  margin: 10px 0 0;
  color: #675849;
  line-height: 1.7;
}

.reader-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  padding: 22px;
  background: rgba(24, 26, 28, 0.58);
  backdrop-filter: blur(10px);
}

.reader-card {
  width: min(1180px, 100%);
  height: min(900px, calc(100vh - 44px));
  margin: 0 auto;
  border-radius: 28px;
  background: #fffefb;
  border: 1px solid rgba(255,255,255,0.8);
  box-shadow: 0 30px 90px rgba(0,0,0,0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.reader-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid #eee1d0;
  background: #fffaf1;
}

.reader-content {
  flex: 1;
  overflow: auto;
  padding: 34px;
  font-size: 1.15em;
  line-height: 2.05;
}

.reader-content .token {
  width: max-content;
  min-width: calc((var(--han-size) + 3px) * 1.15);
  margin-right: calc(var(--gap) + 1px);
  margin-bottom: 10px;
  padding: 0 3px;
  overflow: visible;
}

.reader-content .jp {
  font-size: calc(var(--jyut-size) * 1.25);
  color: #455d72;
  max-width: 9.4ch;
}

.reader-content .han,
.reader-content .punct {
  font-size: calc(var(--han-size) * 1.25);
}

@media (max-width: 720px) {
  .hero { align-items: flex-start; flex-direction: column; padding: 22px; }
  .badge { width: 100px; height: 100px; border-radius: 24px; }
  .panel-title, .reader-head { align-items: flex-start; flex-direction: column; }
  .settings-grid { grid-template-columns: 1fr; }
  textarea { font-size: 18px; }
  .annotated-output { padding: 16px 54px 16px 16px; }
  .reader-overlay { padding: 10px; }
  .reader-card { height: calc(100vh - 20px); border-radius: 20px; }
  .reader-content { padding: 22px; }
}

@media print {
  .input-panel, .settings-panel, .copy-actions, .help-panel, .toolbar, .ghost-btn, .zoom-btn { display: none !important; }
  body { background: white; }
  .panel, .hero { box-shadow: none; border: none; }
}
