:root {
  color-scheme: light;
  font-family:
    -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", sans-serif;
  --ink: #25324a;
  --muted: #626f88;
  --surface: #fffefa;
  --background: #fffaf0;
  --line: #d8deeb;
  --brand: #4163a1;
  --brand-dark: #2f4b83;
  --brand-blue-soft: #e2e8f4;
  --brand-yellow: #f9d387;
  --brand-yellow-soft: #fff1cf;
  --accent: #f49882;
  --accent-soft: #fde3dc;
  --focus: #4163a1;
  --danger: #a43d37;
  --shadow: 0 10px 30px rgb(47 75 131 / 11%);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--background);
  color: var(--ink);
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 4px solid color-mix(in srgb, var(--focus) 58%, white);
  outline-offset: 3px;
}

.app {
  min-height: 100dvh;
}

.settings-view {
  min-height: 100dvh;
  padding:
    max(24px, env(safe-area-inset-top))
    max(26px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(26px, env(safe-area-inset-left));
}

.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 750;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2.45rem);
  line-height: 1.15;
}

.save-status {
  flex: none;
  min-width: 7em;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgb(255 255 255 / 78%);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.save-status[data-state="saved"] {
  border-color: #aebddd;
  color: var(--brand-dark);
}

.save-status[data-state="error"] {
  border-color: #e0aaa6;
  color: var(--danger);
}

.settings-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgb(255 254 250 / 86%);
  box-shadow: 0 4px 18px rgb(47 75 131 / 7%);
}

.layout-picker {
  min-width: 220px;
  margin: 0;
  padding: 0;
  border: 0;
}

.layout-picker legend {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border-radius: 14px;
  background: var(--brand-blue-soft);
}

.segmented-control button {
  min-height: 46px;
  padding: 8px 18px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}

.segmented-control button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 2px 8px rgb(47 75 131 / 15%);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.primary-button,
.secondary-button,
.lock-button,
.card-action {
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 13px;
  font-weight: 720;
}

.primary-button {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: white;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.lock-button {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: white;
}

.lock-button::after {
  position: absolute;
  inset: auto 0 0;
  height: 0;
  background: rgb(255 255 255 / 26%);
  content: "";
  transition: height 2s linear;
}

.lock-button.is-holding::after {
  height: 100%;
}

.lock-button span {
  display: inline-block;
  margin-right: 7px;
  color: var(--brand-yellow);
  font-size: 0.65rem;
}

.swap-instruction {
  min-height: 1.5em;
  max-width: 1400px;
  margin: 0 auto 12px;
  color: var(--brand);
  font-weight: 700;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  max-width: 1400px;
  margin: 0 auto;
}

.edit-grid[data-layout="2x3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.edit-card {
  min-width: 0;
  padding: 14px;
  border: 2px solid transparent;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.edit-card.is-swap-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow);
}

.edit-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.slot-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-yellow-soft);
  color: var(--brand);
  font-weight: 800;
}

.swap-button {
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.photo-button {
  display: grid;
  width: 100%;
  aspect-ratio: 4 / 3;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border: 2px dashed #b4bfd6;
  border-radius: 16px;
  background: #f1f4fa;
  color: var(--brand);
}

.photo-button.has-photo {
  border-style: solid;
  border-color: #d8deeb;
  background: #f4f6fb;
}

.photo-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.photo-placeholder {
  display: grid;
  gap: 8px;
  place-items: center;
  font-weight: 750;
}

.photo-placeholder::before {
  content: "+";
  font-size: 2rem;
  font-weight: 400;
  line-height: 1;
}

.audio-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
}

.audio-status {
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.audio-status strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-action {
  min-width: 82px;
  border: 1px solid var(--line);
  background: #faf8f3;
  color: var(--ink);
}

.card-action.recording {
  border-color: var(--danger);
  background: #fff0ef;
  color: var(--danger);
}

.card-action:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.clear-card-button {
  width: 100%;
  min-height: 40px;
  margin-top: 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

.clear-card-button:not(:disabled):active {
  background: #f3e8e4;
  color: var(--danger);
}

.settings-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  max-width: 1400px;
  margin: 22px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}

.settings-footer p {
  margin: 0;
}

.child-view {
  position: fixed;
  inset: 0;
  overflow: hidden;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background: #dce4f3;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.child-grid {
  display: grid;
  width: 100%;
  height: 100%;
  gap: clamp(12px, 2vw, 24px);
}

.child-grid[data-layout="2x2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.child-grid[data-layout="2x3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.communication-card {
  --photo-inset: clamp(10px, 1.5vw, 22px);
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border: clamp(4px, 0.6vw, 8px) solid white;
  border-radius: clamp(22px, 3vw, 38px);
  background: #fffdf7;
  box-shadow:
    0 9px 0 #a9b6d0,
    0 15px 26px rgb(47 75 131 / 20%);
  transform: translateY(0) scale(1);
  transition:
    transform 70ms ease,
    filter 70ms ease,
    border-color 70ms ease,
    box-shadow 70ms ease;
  touch-action: none;
}

.communication-card img {
  position: absolute;
  top: var(--photo-inset);
  left: var(--photo-inset);
  width: calc(100% - var(--photo-inset) - var(--photo-inset));
  height: calc(100% - var(--photo-inset) - var(--photo-inset));
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.communication-card.is-empty {
  border-color: rgb(255 255 255 / 52%);
  background: rgb(245 246 245 / 38%);
  box-shadow: none;
}

.communication-card.is-pressed {
  border-color: var(--brand);
  filter: brightness(0.88);
  box-shadow:
    0 3px 0 #7f93bd,
    0 7px 15px rgb(47 75 131 / 22%);
  transform: translateY(6px) scale(0.97);
}

.communication-card.is-speaking {
  border-color: var(--accent);
}

.unlock-zone {
  position: absolute;
  top: 0;
  z-index: 3;
  width: 86px;
  height: 86px;
  pointer-events: none;
}

.unlock-zone-left {
  left: 0;
}

.unlock-zone-right {
  right: 0;
}

.portrait-prompt {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 30px;
  background: var(--brand);
  color: white;
  text-align: center;
}

.portrait-prompt strong {
  font-size: 1.6rem;
}

.portrait-prompt span {
  color: #eef1f8;
}

.rotate-device {
  width: 90px;
  height: 128px;
  margin-bottom: 18px;
  border: 5px solid white;
  border-radius: 15px;
  transform: rotate(90deg);
}

.confirm-dialog {
  width: min(500px, calc(100% - 40px));
  padding: 0;
  border: 0;
  border-radius: 24px;
  box-shadow: 0 24px 80px rgb(31 43 72 / 40%);
}

.confirm-dialog::backdrop {
  background: rgb(31 43 72 / 62%);
}

.confirm-dialog form {
  padding: 28px;
}

.confirm-dialog h2 {
  margin: 0 0 8px;
  font-size: 1.55rem;
}

.confirm-dialog p {
  margin: 0 0 24px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 200;
  max-width: min(440px, calc(100% - 48px));
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--brand-dark);
  color: white;
  box-shadow: 0 12px 42px rgb(31 43 72 / 30%);
  font-weight: 650;
}

.toast[data-kind="error"] {
  background: #862f2b;
}

@media (max-width: 900px) {
  .settings-toolbar,
  .settings-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    justify-content: flex-start;
  }

  .edit-grid[data-layout="2x3"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (orientation: portrait) {
  .portrait-prompt {
    display: grid;
  }
}

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