:root {
  color-scheme: light;
  --page: #f6f4ef;
  --surface: #ffffff;
  --surface-soft: #fbf7ef;
  --ink: #2f2d2a;
  --muted: #6e6860;
  --line: #ddd4c6;
  --accent: #b86f45;
  --accent-deep: #8f4d2b;
  --care: #327f78;
  --urgent: #b33f35;
  --focus: #f3c14b;
  --shadow: 0 10px 28px rgba(48, 39, 30, 0.1);
  --choice-size: 1.35rem;
  --focus-size: 3rem;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100dvh;
  background: var(--page);
  color: var(--ink);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  overflow: hidden;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  line-height: 1;
}

.icon-button {
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--line);
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 900;
}

.caregiver-settings {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 18;
  opacity: 0.64;
  box-shadow: var(--shadow);
}

.caregiver-settings:is(:hover, :focus-visible) {
  opacity: 1;
}

.message-panel,
.scan-panel,
.focus-panel {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.message-panel {
  padding: 10px;
}

.scan-controls button,
.primary {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  background: #eee7dc;
  color: var(--ink);
  font-weight: 800;
}

.scan-action.speak,
.primary {
  background: var(--care);
  color: #fff;
}

.output {
  min-height: 72px;
  max-height: min(22dvh, 160px);
  padding: 14px;
  border: 2px solid #ead9bd;
  border-radius: 12px;
  background: var(--surface-soft);
  font-size: clamp(1.55rem, 5vw, 2.8rem);
  font-weight: 900;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: anywhere;
  overflow-y: auto;
}

.output.placeholder {
  color: transparent;
}

.focus-panel {
  min-height: 82px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  background: #fffdf8;
}

.focus-current {
  min-width: 0;
  font-size: var(--focus-size);
  font-weight: 900;
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.focus-next {
  display: flex;
  gap: 6px;
  max-width: min(36vw, 360px);
  overflow: hidden;
}

.focus-next span {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 9px 12px;
  border-radius: 12px;
  background: #eee7dc;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 900;
  text-align: center;
}

.scan-panel {
  padding: 10px;
}

.scan-controls {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
}

.progress {
  height: 12px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5dccf;
}

#progress-bar {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--focus), var(--accent));
}

.select-current {
  width: 100%;
  min-height: 58px;
  margin-top: 10px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  font-weight: 900;
}

.tab-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.tab-button {
  min-height: 62px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font-size: clamp(1rem, 2.8vw, 1.35rem);
  font-weight: 900;
  box-shadow: 0 3px 12px rgba(48, 39, 30, 0.07);
}

.tab-button.active {
  border-color: var(--care);
  background: #e8f4f1;
}

.view {
  display: none;
  min-height: 0;
  overflow: auto;
  padding-bottom: 8px;
  overscroll-behavior: contain;
}

.view.active {
  display: block;
}

.category-list,
.word-list,
.kana-board,
.body-grid,
.symptom-grid,
.number-board {
  display: grid;
  gap: 8px;
}

.category-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 10px;
}

.word-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kana-board {
  grid-template-columns: 1fr;
}

.kana-row {
  display: grid;
  grid-template-columns: 4rem repeat(5, minmax(0, 1fr));
  gap: 7px;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.38);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.kana-label {
  display: grid;
  place-items: center;
  min-height: 58px;
  border-radius: 12px;
  background: #eee7dc;
  color: var(--muted);
  font-weight: 900;
}

.body-grid,
.symptom-grid,
.number-board {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.body-grid {
  margin-bottom: 10px;
}

.choice,
.key {
  position: relative;
  min-height: 64px;
  padding: 12px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font-size: var(--choice-size);
  font-weight: 900;
  text-align: center;
  box-shadow: 0 3px 12px rgba(48, 39, 30, 0.07);
}

.category-list .choice {
  min-height: 72px;
  font-size: clamp(1.05rem, 3.4vw, 1.45rem);
}

.choice.urgent {
  border-color: #d7a69f;
  background: #fff1ee;
}

.choice.posture {
  border-color: #d8bb8f;
  background: #fff7e8;
}

.key {
  min-height: 58px;
}

.body-choice {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.body-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: #e8f4f1;
  color: var(--care);
  font-family: ui-rounded, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1;
}

.body-label {
  min-width: 0;
}

.highlight {
  border-color: var(--accent-deep) !important;
  background: #fff4d8 !important;
  color: #2a1c12 !important;
  outline: 5px solid rgba(243, 193, 75, 0.42);
  transform: translateY(-1px);
}

.row-highlight {
  border-color: var(--accent-deep);
  background: #fff4d8;
  box-shadow: 0 0 0 5px rgba(243, 193, 75, 0.34);
}

.row-highlight .kana-label {
  background: var(--accent);
  color: #fff;
}

.selected-category {
  border-color: var(--care) !important;
  background: #e8f4f1 !important;
}

.countdown {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  background: rgba(47, 45, 42, 0.42);
  color: #fff;
  font-size: clamp(4rem, 22vw, 12rem);
  font-weight: 900;
}

.countdown.active {
  display: grid;
}

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(47, 45, 42, 0.34);
}

.settings-panel.open {
  display: grid;
}

.settings-card {
  width: min(560px, 100%);
  padding: 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.settings-head h2 {
  font-size: 1.4rem;
}

.setting-row {
  display: grid;
  grid-template-columns: 7rem 1fr 4.5rem;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  font-weight: 900;
}

.setting-row input {
  width: 100%;
  accent-color: var(--accent);
}

.setting-row select {
  min-height: 48px;
  width: 100%;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 900;
}

.setting-row strong {
  text-align: right;
}

.test-button {
  min-height: 48px;
  border-radius: 12px;
  background: var(--care);
  color: #fff;
  font-weight: 900;
}

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

@media (min-width: 820px) {
  .app-shell {
    max-width: 1080px;
    margin: 0 auto;
    padding-inline: 18px;
  }

  .word-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .scan-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app-shell {
    gap: 8px;
    padding-inline: 8px;
  }

  h1 {
    font-size: 1.45rem;
  }

  .output {
    max-height: 108px;
    min-height: 62px;
    font-size: clamp(1.35rem, 7vw, 2rem);
  }

  .focus-panel {
    min-height: 68px;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .focus-current {
    font-size: min(var(--focus-size), 2.6rem);
  }

  .focus-next {
    max-width: 100%;
  }

  .focus-next span {
    min-width: 48px;
    padding: 6px 9px;
  }

  .scan-controls button {
    min-height: 48px;
    padding: 0 8px;
  }

  .select-current {
    min-height: 52px;
  }

  .tab-list,
  .category-list,
  .word-list,
  .body-grid,
  .symptom-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kana-row {
    grid-template-columns: 3rem repeat(5, minmax(0, 1fr));
    gap: 5px;
    padding: 6px;
  }

  .choice,
  .key {
    min-height: 58px;
    padding: 9px 7px;
  }

  .body-choice {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .body-icon {
    width: 48px;
    height: 48px;
  }

  .setting-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .setting-row strong {
    text-align: left;
  }
}
