:root {
  color-scheme: light;
  --ink: #18312e;
  --muted: #5f6c68;
  --paper: #fbfaf6;
  --warm: #f4efe3;
  --line: #d9d5c9;
  --teal: #0f7068;
  --teal-dark: #09524d;
  --teal-soft: #dcefeb;
  --amber: #dc8a2d;
  --amber-soft: #f8e6cd;
  --red: #a4473e;
  --white: #ffffff;
  --shadow: 0 18px 48px rgba(38, 54, 49, 0.12);
  --radius: 22px;
  --font-body: "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-display: "BIZ UDPMincho", "Yu Mincho", serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--warm);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 2%, rgba(255, 255, 255, 0.92) 0 9rem, transparent 25rem),
    linear-gradient(135deg, rgba(15, 112, 104, 0.035) 25%, transparent 25%) 0 0 / 28px 28px,
    var(--warm);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

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

button,
.file-label {
  touch-action: manipulation;
}

button:focus-visible,
textarea:focus-visible,
select:focus-visible,
.file-label:focus-within {
  outline: 4px solid rgba(220, 138, 45, 0.46);
  outline-offset: 3px;
}

button {
  color: inherit;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  transform: translateY(-150%);
  padding: 10px 16px;
  border-radius: 10px;
  color: var(--white);
  background: var(--teal-dark);
}

.skip-link:focus {
  transform: translateY(0);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 78px;
  padding: 12px max(20px, env(safe-area-inset-left)) 12px max(20px, env(safe-area-inset-right));
  border-bottom: 1px solid rgba(24, 49, 46, 0.12);
  background: rgba(251, 250, 246, 0.93);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 46px;
  height: 46px;
  border-radius: 50% 50% 46% 54%;
  background: var(--teal);
  box-shadow: 0 7px 0 rgba(15, 112, 104, 0.15);
}

.brand-mark span {
  display: block;
  width: 4px;
  border-radius: 10px;
  background: var(--white);
}

.brand-mark span:nth-child(1) { height: 12px; }
.brand-mark span:nth-child(2) { height: 24px; }
.brand-mark span:nth-child(3) { height: 16px; }

.brand-name,
.brand-sub,
.eyebrow,
.panel-intro p,
.kana-help p,
.setting-section p {
  margin: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.03em;
}

.brand-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.offline-badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 5px 12px;
  border: 1px solid #a8c9c4;
  border-radius: 999px;
  color: var(--teal-dark);
  background: #eef8f5;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.offline-badge::before {
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--teal);
  content: "";
}

.offline-badge.is-offline {
  border-color: #d8b27a;
  color: #744716;
  background: #fff4e4;
}

.offline-badge.is-offline::before {
  background: var(--amber);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 48px;
  min-height: 48px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.icon-button > span:first-child {
  font-size: 22px;
}

.app-shell {
  width: min(1180px, calc(100% - 36px));
  margin: 26px auto 80px;
}

.composer,
.input-panel {
  border: 1px solid rgba(24, 49, 46, 0.11);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.composer {
  position: relative;
  padding: clamp(18px, 3vw, 32px);
  overflow: hidden;
}

.composer::after {
  position: absolute;
  top: -90px;
  right: -70px;
  width: 230px;
  height: 230px;
  border: 34px solid rgba(15, 112, 104, 0.06);
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.composer-heading,
.section-heading-row,
.history-intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  line-height: 1.35;
}

h1 {
  margin: 2px 0 14px;
  font-size: clamp(22px, 4vw, 32px);
}

h2 {
  margin: 2px 0 0;
  font-size: 29px;
}

h3 {
  margin: 0 0 8px;
  font-size: 22px;
}

#message {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  min-height: 150px;
  resize: vertical;
  padding: 19px 21px;
  border: 3px solid #b7c7c3;
  border-radius: 17px;
  color: #102b28;
  background: var(--white);
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 700;
  line-height: 1.55;
  caret-color: var(--teal);
}

#message::placeholder {
  color: #7d8a87;
  font-size: clamp(16px, 2.4vw, 21px);
  font-weight: 500;
}

#message:focus {
  border-color: var(--teal);
}

.edit-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 50px;
  margin-top: 10px;
}

.utility-button,
.text-button,
.danger-text-button {
  border: 0;
  background: transparent;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.utility-button {
  min-height: 46px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f7f5ef;
  text-decoration: none;
}

.text-button {
  min-height: 44px;
  color: var(--teal-dark);
}

.danger-text-button {
  min-height: 44px;
  padding: 0;
  color: var(--red);
}

.character-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.voice-actions {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(170px, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.speak-button,
.show-button {
  min-height: 84px;
  border-radius: 18px;
  cursor: pointer;
}

.speak-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  border: 0;
  color: var(--white);
  background: linear-gradient(145deg, #117d73, var(--teal-dark));
  box-shadow: 0 10px 0 #063c38, 0 17px 28px rgba(9, 82, 77, 0.2);
  transform: translateY(0);
}

.speak-button:hover {
  background: linear-gradient(145deg, #0c6d65, #064a45);
}

.speak-button:active {
  box-shadow: 0 4px 0 #063c38;
  transform: translateY(6px);
}

.speak-button strong,
.speak-button small {
  display: block;
}

.speak-button strong {
  font-size: clamp(25px, 3vw, 32px);
  line-height: 1.2;
  letter-spacing: 0.04em;
}

.speak-button small {
  margin-top: 3px;
  color: #d8f2ef;
  font-size: 12px;
  font-weight: 600;
}

.speak-icon {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 34px;
}

.speak-icon i {
  display: block;
  width: 5px;
  border-radius: 10px;
  background: var(--white);
}

.speak-icon i:nth-child(1) { height: 17px; }
.speak-icon i:nth-child(2) { height: 32px; }
.speak-icon i:nth-child(3) { height: 23px; }

.show-button {
  border: 2px solid var(--teal);
  color: var(--teal-dark);
  background: var(--teal-soft);
  font-size: 21px;
  font-weight: 800;
}

.status-message {
  min-height: 28px;
  margin: 11px 0 -8px;
  color: var(--red);
  font-weight: 700;
  text-align: center;
}

.input-panel {
  margin-top: 24px;
  overflow: hidden;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--line);
  background: #e8e3d7;
}

.mode-tab {
  min-height: 66px;
  padding: 9px 14px;
  border: 0;
  border-radius: 15px 15px 0 0;
  color: #45534f;
  background: transparent;
  font-size: clamp(16px, 2.4vw, 21px);
  font-weight: 800;
  cursor: pointer;
}

.mode-tab.is-active {
  position: relative;
  color: var(--teal-dark);
  background: var(--paper);
}

.mode-tab.is-active::after {
  position: absolute;
  right: 24%;
  bottom: 0;
  left: 24%;
  height: 5px;
  border-radius: 5px 5px 0 0;
  background: var(--teal);
  content: "";
}

.tab-panel {
  padding: clamp(17px, 3vw, 30px);
}

.panel-intro {
  margin-bottom: 16px;
}

.panel-intro > p,
.kana-help p:first-child {
  font-size: 19px;
  font-weight: 800;
}

.category-filters {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-bottom: 3px;
  overflow-x: auto;
}

.category-filter {
  min-width: 72px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid #b9c1bd;
  border-radius: 999px;
  background: var(--white);
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.category-filter.is-active {
  border-color: var(--ink);
  color: var(--white);
  background: var(--ink);
}

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

.phrase-button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  min-height: 106px;
  padding: 15px 16px;
  border: 2px solid #c6d1ce;
  border-radius: 16px;
  background: var(--white);
  box-shadow: 0 5px 0 #d7d8d0;
  font-size: clamp(17px, 2.2vw, 22px);
  font-weight: 800;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.phrase-button:hover {
  border-color: var(--teal);
  background: #f2fbf8;
}

.phrase-button:active {
  box-shadow: 0 2px 0 #c8cec9;
  transform: translateY(3px);
}

.phrase-button.featured {
  border-color: #8dbbb5;
  background: var(--teal-soft);
}

.phrase-category {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.phrase-button::after {
  position: absolute;
  right: 12px;
  bottom: 10px;
  color: var(--teal);
  content: "▶";
  font-size: 11px;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 32px;
  border: 2px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

.kana-help {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 13px;
}

.kana-help p:last-child {
  color: var(--muted);
  font-size: 13px;
}

.kana-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(48px, 1fr));
  gap: 8px;
}

.kana-button,
.modifier-grid button {
  min-height: 61px;
  border: 1px solid #b8c4c0;
  border-radius: 13px;
  background: var(--white);
  box-shadow: 0 4px 0 #d2d4ce;
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 800;
  cursor: pointer;
}

.kana-button:hover,
.modifier-grid button:hover {
  border-color: var(--teal);
  background: #eff8f5;
}

.kana-button:active,
.modifier-grid button:active {
  box-shadow: 0 1px 0 #cfd2cc;
  transform: translateY(3px);
}

.modifier-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(70px, 1fr));
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.modifier-grid button {
  min-height: 66px;
  color: var(--teal-dark);
  background: var(--teal-soft);
  font-size: 22px;
}

.modifier-grid small {
  display: block;
  font-size: 10px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-button {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 70px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  font-size: 19px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.history-button span:last-child {
  color: var(--teal);
  font-size: 13px;
}

.settings-dialog {
  width: min(760px, calc(100% - 24px));
  max-height: min(880px, calc(100vh - 28px));
  padding: 0;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 30px 90px rgba(15, 31, 28, 0.36);
}

.settings-dialog::backdrop,
.large-dialog::backdrop {
  background: rgba(13, 29, 27, 0.7);
  backdrop-filter: blur(5px);
}

.dialog-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.96);
}

.dialog-close,
.large-dialog-close {
  display: grid;
  place-items: center;
  min-width: 52px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--white);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.settings-content {
  padding: 0 22px 30px;
}

.setting-section {
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.setting-section:last-child {
  border-bottom: 0;
}

.setting-section > p,
.section-heading-row p {
  color: var(--muted);
  font-size: 15px;
}

.setting-label {
  display: block;
  margin: 15px 0 6px;
  font-size: 15px;
  font-weight: 800;
}

.voice-select {
  width: 100%;
  min-height: 54px;
  padding: 9px 42px 9px 13px;
  border: 2px solid #aebbb7;
  border-radius: 12px;
  color: var(--ink);
  background: var(--white);
  font-weight: 700;
}

.voice-status {
  min-height: 24px;
  margin-top: 7px !important;
  color: var(--teal-dark) !important;
  font-size: 13px !important;
  font-weight: 700;
}

.speed-options,
.transfer-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 14px;
}

.speed-options button,
.secondary-button,
.primary-small,
.file-label {
  min-height: 49px;
  padding: 9px 15px;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
}

.speed-options button,
.secondary-button,
.file-label {
  border: 1px solid #aebbb7;
  background: var(--white);
}

.speed-options button.is-active {
  border-color: var(--teal);
  color: var(--white);
  background: var(--teal);
}

.secondary-button {
  margin-top: 12px;
}

.primary-small {
  border: 0;
  color: var(--white);
  background: var(--teal-dark);
}

.phrase-form {
  margin: 18px 0;
  padding: 18px;
  border: 2px solid #a7c9c4;
  border-radius: 16px;
  background: #edf7f4;
}

.phrase-form label {
  display: block;
  margin: 10px 0 5px;
  font-weight: 800;
}

.phrase-form textarea,
.phrase-form select {
  width: 100%;
  padding: 12px;
  border: 1px solid #9dada8;
  border-radius: 10px;
  background: var(--white);
}

.form-actions {
  justify-content: flex-end;
}

.form-actions .secondary-button {
  margin-top: 0;
}

.phrase-edit-list {
  display: grid;
  gap: 8px;
  margin-top: 17px;
}

.phrase-edit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}

.phrase-edit-row p {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

.phrase-edit-row small {
  color: var(--muted);
}

.phrase-edit-actions {
  display: flex;
  gap: 5px;
}

.phrase-edit-actions button {
  min-width: 47px;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f7f5ef;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.file-label {
  display: inline-flex;
  align-items: center;
}

.reset-section {
  opacity: 0.86;
}

.large-dialog {
  width: calc(100vw - 28px);
  max-width: none;
  height: calc(100vh - 28px);
  max-height: none;
  margin: 14px;
  padding: 20px;
  border: 0;
  border-radius: 18px;
  color: #102320;
  background: #fffef9;
}

.large-dialog-close {
  position: fixed;
  top: 29px;
  right: 29px;
  width: auto;
  padding: 0 17px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 800;
}

#largeText {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 80px);
  margin: 0;
  padding: 65px 3vw 30px;
  font-family: var(--font-display);
  font-size: clamp(46px, 10vw, 120px);
  font-weight: 900;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
}

.speaking-bar {
  position: fixed;
  z-index: 50;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: min(520px, calc(100% - 32px));
  min-height: 67px;
  margin: auto;
  padding: 9px 10px 9px 18px;
  border-radius: 18px;
  color: var(--white);
  background: #132d29;
  box-shadow: 0 12px 42px rgba(0, 0, 0, 0.28);
  font-weight: 800;
}

.speaking-bar[hidden] {
  display: none;
}

.speaking-bar button {
  min-width: 82px;
  min-height: 48px;
  margin-left: auto;
  border: 0;
  border-radius: 12px;
  color: #4a1a16;
  background: #ffd7d1;
  font-weight: 900;
  cursor: pointer;
}

.speaking-animation {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 30px;
}

.speaking-animation i {
  width: 4px;
  height: 10px;
  border-radius: 4px;
  background: #80d2c8;
  animation: voice-wave 0.8s ease-in-out infinite alternate;
}

.speaking-animation i:nth-child(2) { animation-delay: 0.18s; }
.speaking-animation i:nth-child(3) { animation-delay: 0.36s; }
.speaking-animation i:nth-child(4) { animation-delay: 0.54s; }

@keyframes voice-wave {
  to { height: 29px; }
}

.toast {
  position: fixed;
  z-index: 70;
  top: 90px;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 30px);
  padding: 11px 17px;
  border-radius: 999px;
  color: var(--white);
  background: #152d29;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22);
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  transform: translateX(-50%);
}

.no-script {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 30px;
  color: var(--white);
  background: var(--ink);
  font-size: 24px;
  text-align: center;
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  body {
    font-size: 16px;
  }

  .topbar {
    min-height: 66px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .brand-mark {
    width: 41px;
    height: 41px;
  }

  .brand-name {
    font-size: 20px;
  }

  .brand-sub,
  .offline-badge,
  .desktop-only {
    display: none;
  }

  .icon-button {
    padding: 5px;
  }

  .app-shell {
    width: calc(100% - 18px);
    margin-top: 10px;
  }

  .composer,
  .input-panel {
    border-radius: 17px;
  }

  .composer {
    padding: 15px;
  }

  h1 {
    margin-bottom: 10px;
  }

  #message {
    min-height: 128px;
    padding: 14px;
    border-width: 2px;
  }

  .voice-actions {
    grid-template-columns: 1fr;
  }

  .speak-button {
    min-height: 80px;
  }

  .show-button {
    min-height: 55px;
  }

  .speak-button small {
    display: none;
  }

  .input-panel {
    margin-top: 12px;
  }

  .mode-tabs {
    padding: 5px 5px 0;
  }

  .mode-tab {
    min-height: 58px;
    padding: 6px 4px;
    line-height: 1.25;
  }

  .tab-panel {
    padding: 14px;
  }

  .phrase-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .phrase-button {
    min-height: 96px;
    padding: 12px;
    border-radius: 13px;
  }

  .kana-help {
    display: block;
  }

  .kana-help p:last-child {
    margin-top: 4px;
  }

  .kana-grid {
    gap: 6px;
  }

  .kana-button {
    min-height: 57px;
    border-radius: 11px;
  }

  .modifier-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
  }

  .modifier-grid button {
    min-width: 0;
  }

  .section-heading-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .settings-content {
    padding-right: 16px;
    padding-left: 16px;
  }

  .phrase-edit-row {
    grid-template-columns: 1fr;
  }

  .phrase-edit-actions button {
    flex: 1;
  }
}

@media (max-width: 390px) {
  .brand-sub {
    display: none;
  }

  .composer-heading .text-button {
    font-size: 14px;
  }

  .edit-actions {
    gap: 5px;
  }

  .utility-button {
    padding-right: 8px;
    padding-left: 8px;
    font-size: 14px;
  }

  .character-count {
    font-size: 12px;
  }

  .phrase-button {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .topbar,
  .input-panel,
  .voice-actions,
  .edit-actions {
    display: none;
  }

  body,
  .composer {
    background: var(--white);
    box-shadow: none;
  }
}
