:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #191919;
  --text-soft: #292929;
  --muted: #8a8a8a;
  --icon: #6f6f6f;
  --line: #e5e5e5;
  --navy: #0f2b46;
  --hover: rgba(0, 0, 0, 0.05);
  --selected: #e7f1fb;
  --danger: #9b2c2c;
  --shadow: 0 8px 32px rgba(15, 23, 42, 0.12);
  --radius: 16px;
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--text);
}

button, textarea, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.topbar-inner,
.modes-inner,
.page {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar-inner {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.key-btn,
.btn-ghost,
.btn-text,
.btn-primary {
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}

.key-btn {
  margin-left: auto;
  background: transparent;
  color: var(--text-soft);
}

.key-btn:hover,
.btn-ghost:hover,
.btn-text:hover {
  background: var(--hover);
}

.key-btn.is-set {
  background: var(--navy);
  color: #fff;
}

.key-btn.is-set:hover {
  background: #183a5c;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: block;
}

.modes {
  padding: 16px 0 0;
}

.mode {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: #ececec;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 600;
}

.mode svg {
  width: 18px;
  height: 18px;
}

.page {
  padding: 16px 0 40px;
}

.translator {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lang-strip,
.pane {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.lang-strip {
  min-height: 56px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 12px;
}

.lang-slot {
  display: flex;
  justify-content: center;
}

.lang-slot.is-end {
  justify-content: center;
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 32px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 600;
}

.lang-btn:hover,
.lang-btn[aria-expanded="true"] {
  background: var(--hover);
}

.lang-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chevron {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: #4d4d4d;
}

.lang-btn[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.swap-btn,
.icon-btn,
.clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--icon);
}

.swap-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-soft);
}

.swap-btn svg,
.icon-btn svg,
.clear-btn svg {
  width: 18px;
  height: 18px;
}

.swap-btn:hover:not(:disabled),
.icon-btn:hover:not(:disabled),
.clear-btn:hover {
  background: var(--hover);
}

.swap-btn:disabled {
  background: rgba(0, 0, 0, 0.03);
  color: rgba(0, 0, 0, 0.25);
}

.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: stretch;
}

.pane {
  min-height: clamp(420px, 58vh, 560px);
  display: flex;
  flex-direction: column;
}

.pane-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

textarea,
.output {
  width: 100%;
  margin: 0;
  padding: 22px 48px 12px 24px;
  border: 0;
  resize: none;
  outline: none;
  background: transparent;
  font-size: 22px;
  font-weight: 400;
  line-height: 1.65;
  color: var(--text);
}

textarea {
  flex: 1;
}

textarea::placeholder {
  color: #9a9a9a;
}

.output {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow: auto;
}

.output.is-error {
  color: var(--danger);
  font-size: 15px;
  line-height: 1.7;
}

.output.is-loading {
  color: var(--muted);
}

.clear-btn {
  position: absolute;
  top: 22px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: #5c5c5c;
}

.pane-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 4px 12px 10px 20px;
}

.char-count,
.status {
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.icon-btn:disabled {
  opacity: 0.35;
}

.icon-btn.is-copied {
  color: var(--navy);
}

.footnote {
  margin: 18px 4px 0;
  color: #8d8d8d;
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.36);
}

.modal {
  width: min(460px, 100%);
  padding: 24px;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

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

.modal p,
.hint {
  margin: 0;
  color: #5c5c5c;
  font-size: 13px;
  line-height: 1.7;
}

.modal label {
  display: block;
  margin: 16px 0 6px;
  font-size: 13px;
  font-weight: 600;
}

.key-field {
  display: flex;
  gap: 8px;
}

.key-field input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cfcfcf;
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
}

.key-field input:focus {
  border-color: #7aa7d6;
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 43, 70, 0.12);
}

.hint {
  margin-top: 8px;
}

.modal .field-error {
  margin-top: 8px;
  color: var(--danger);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
}

.modal-spacer {
  flex: 1;
}

.btn-ghost,
.btn-text {
  background: transparent;
  color: var(--text-soft);
}

.btn-primary {
  background: var(--navy);
  color: #fff;
}

.btn-primary:hover {
  background: #183a5c;
}

.lang-menu {
  position: fixed;
  z-index: 20;
  width: min(560px, calc(100vw - 24px));
  max-height: min(460px, calc(100vh - 24px));
  display: flex;
  flex-direction: column;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

.lang-menu[hidden] {
  display: none;
}

.lang-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  margin-bottom: 8px;
  padding: 0 12px;
  border: 1px solid #cfcfcf;
  border-radius: 10px;
  color: #666;
}

.lang-search:focus-within {
  border-color: #7aa7d6;
  box-shadow: 0 0 0 3px rgba(15, 43, 70, 0.12);
}

.lang-search svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.lang-search input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 15px;
}

.lang-search input::-webkit-search-cancel-button {
  cursor: pointer;
}

.lang-list {
  overflow: auto;
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(var(--rows, 12), auto);
  align-content: start;
  gap: 2px;
  padding-bottom: 4px;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
}

.lang-option:hover,
.lang-option.is-active {
  background: var(--hover);
}

.lang-option.is-selected {
  background: var(--selected);
  font-weight: 600;
}

.lang-option .check {
  width: 16px;
  flex: 0 0 16px;
  color: var(--navy);
  font-size: 13px;
}

.lang-empty {
  grid-column: 1 / -1;
  padding: 18px 8px;
  color: var(--muted);
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(8px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}

textarea:focus-visible {
  outline: none;
}

@media (max-width: 800px) {
  .panes {
    grid-template-columns: 1fr;
  }

  .lang-list {
    grid-auto-flow: row;
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }

  .pane {
    min-height: 280px;
  }

  textarea,
  .output {
    font-size: 18px;
    padding-top: 18px;
  }

  .topbar-inner,
  .modes-inner,
  .page {
    width: min(1120px, calc(100% - 20px));
  }
}
