:root {
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --line: #d8d8d8;
  --bg: #fff;
  --soft: #f6f6f6;
  --accent: #1a1a1a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 "Segoe UI", "Noto Sans", "PingFang HK", "Microsoft JhengHei",
    sans-serif;
}

body {
  max-width: 64rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

h1 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
}

h2 {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.bar {
  margin-bottom: 1.25rem;
}

.layout {
  display: grid;
  grid-template-columns: 13rem 1fr;
  gap: 1.75rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.toggles {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toggles legend {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0;
  margin-bottom: 0.25rem;
}

.toggles label {
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

@media (max-width: 40rem) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
  }
}

textarea,
button,
input[type="text"] {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
}

button,
input[type="text"] {
  padding: 0.25rem 0.5rem;
}

button {
  cursor: pointer;
  background: var(--soft);
}

button:hover {
  border-color: #aaa;
}

.status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.panel {
  margin-bottom: 1.35rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.panel-head h2,
.panel > h2 {
  margin-bottom: 0.4rem;
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 0.7rem 0.8rem;
  min-height: calc(2em * 1.5 + 1.4rem);
}

.hint {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.editor {
  min-height: 3.5rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--soft);
  word-break: break-word;
}

textarea.output {
  min-height: calc(1em * 1.5 + 1.4rem);
  overflow: hidden;
  resize: none;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.ruby {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: bottom;
  margin: 0 0.12em 0.2em;
}

.ruby .rt {
  font-size: 0.7rem;
  line-height: 1.2;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.ruby .rb {
  font-size: 1.2rem;
  line-height: 1.25;
}

.ruby.multi {
  cursor: pointer;
}

.ruby.multi .rb {
  border-bottom: 1px solid #888;
}

.ruby.override .rt {
  color: var(--text);
  font-weight: 600;
}

#cand-popup {
  position: fixed;
  z-index: 20;
  min-width: 12rem;
  max-width: min(22rem, calc(100vw - 16px));
  padding: 0.55rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

.cand-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
}

.cand-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.05rem;
  padding: 0.25rem 0.45rem;
}

.cand-btn.active {
  border-color: var(--text);
  background: #eee;
}

.cand-jp {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
}

.cand-yale {
  font-size: 0.75rem;
  color: var(--muted);
}

.cand-custom-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.cand-custom {
  width: 100%;
}

.cand-tones {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.2rem;
  margin-bottom: 0.45rem;
}

.sidebar .cand-tones {
  margin-bottom: 0;
}

.tone-btn {
  padding: 0.15rem 0;
  min-width: 0;
}

.cand-error {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  color: #8a1f1f;
}

.cand-apply {
  width: 100%;
}

[hidden] {
  display: none !important;
}
