:root {
  color-scheme: light;
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #20313a;
  --muted: #66757d;
  --paper: #fffdf7;
  --page: #f7f1e3;
  --blue: #2b6f89;
  --blue-dark: #1f5368;
  --blue-soft: #eaf6f9;
  --green: #397150;
  --gold: #d69b2d;
  --line: #d9d5c9;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { min-width: 640px; margin: 0; background: var(--page); color: var(--ink); -webkit-text-size-adjust: 100%; }
button, textarea { font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }

.journal-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1180px, 100%);
  height: 100%;
  margin: 0 auto;
  padding: max(9px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(11px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.profile-summary { display: flex; align-items: center; gap: 11px; font-weight: 800; white-space: nowrap; }
.quiet-button {
  min-height: 44px;
  padding: 7px 13px;
  border: 2px solid #a9bcc2;
  border-radius: 12px;
  background: white;
  color: var(--blue-dark);
  font-weight: 800;
}
.eyebrow { margin: 0 0 4px; color: var(--blue-dark); font-size: 13px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }

.journal-intro {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  padding: 18px;
  border: 2px solid white;
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgb(69 67 57 / 14%);
}
.intro-heading h2 { margin: 0; font-size: clamp(30px, 4vw, 42px); }
.journal-choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; min-height: 0; }
.journal-choice {
  display: grid;
  min-height: 0;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 22px;
  border: 3px solid #b8c9ce;
  border-radius: 22px;
  background: white;
  color: var(--ink);
  text-align: center;
}
.journal-choice .choice-icon { font-size: clamp(50px, 7vw, 76px); line-height: 1; }
.journal-choice strong { color: var(--blue-dark); font-size: clamp(22px, 2.6vw, 30px); }
.journal-choice > span:last-child { max-width: 320px; color: var(--muted); font-size: 17px; font-weight: 700; }

.journal-workspace, .history-view, .history-detail, .journal-quiz { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; grid-row: 1 / -1; }
.practice-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 66px; padding: 0 3px 9px; }
.practice-header > div:first-child { min-width: 0; }
.practice-header h1 { margin: 2px 0 0; font-size: clamp(28px, 3.4vw, 39px); line-height: 1; }
.practice-header > p { margin: 0; color: var(--muted); font-size: 17px; font-weight: 750; }
.practice-header-actions { display: flex; align-items: center; gap: 13px; }
.back-button, .history-button {
  min-height: 40px;
  padding: 6px 11px;
  border: 0;
  background: transparent;
  color: var(--blue-dark);
  font-size: 14px;
  font-weight: 850;
}
.history-button { border: 2px solid #9eb5bc; border-radius: 11px; background: white; font-size: 16px; }

.editor-card {
  position: relative;
  display: block;
  isolation: isolate;
  min-height: 0;
  overflow: hidden;
  padding: 18px;
  border: 2px solid white;
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgb(69 67 57 / 14%);
}
.writing-panel { position: relative; z-index: 2; display: grid; grid-template-rows: auto minmax(130px, 1fr) auto auto; width: 100%; height: 100%; min-width: 0; min-height: 0; }
.journal-date { margin: 0 0 3px; color: var(--blue-dark); font-size: 17px; font-weight: 850; }
.writing-panel h2 { margin: 0; font-size: clamp(25px, 3.1vw, 36px); line-height: 1.08; }
.writing-help { margin: 6px 0 11px; color: var(--muted); font-size: 16px; font-weight: 650; }
#journal-text {
  width: 100%;
  min-height: 0;
  resize: none;
  padding: 15px;
  border: 3px solid #91a9b1;
  border-radius: 16px;
  background: rgb(255 255 255 / 58%);
  box-shadow: 0 3px 12px rgb(55 69 72 / 8%);
  color: var(--ink);
  font-size: clamp(22px, 2.7vw, 31px);
  font-weight: 650;
  line-height: 1.38;
}
#journal-text:focus { background: rgb(255 255 255 / 68%); }
#journal-text[readonly] { background: rgb(244 247 242 / 68%); }
.journal-message { min-height: 25px; margin: 7px 0 5px; color: #765b20; font-weight: 750; }
.save-actions { display: flex; justify-content: flex-end; gap: 12px; }
.primary-button, .secondary-button {
  display: inline-flex;
  min-width: 130px;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border-radius: 15px;
  font-size: 19px;
  font-weight: 850;
}
.primary-button { border: 0; background: var(--blue); box-shadow: 0 3px 0 var(--blue-dark); color: white; }
.secondary-button { border: 3px solid var(--blue); background: white; color: var(--blue-dark); }
.primary-button:disabled, .secondary-button:disabled { cursor: default; opacity: .45; box-shadow: none; }

.picture-panel {
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
}
.picture-panel::after {
  position: absolute;
  z-index: 2;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgb(255 253 247 / 97%) 0%,
    rgb(255 253 247 / 86%) 28%,
    rgb(255 253 247 / 45%) 62%,
    rgb(255 253 247 / 6%) 100%
  );
  content: "";
}
.picture-placeholder, .picture-waiting { display: none !important; }
#journal-picture {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(1.08) contrast(1.04) brightness(1.01);
  opacity: 1;
}
.task-finish-button { min-width: 112px; border: 3px solid white; }

.journal-quiz-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 20px;
  border: 2px solid white;
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgb(69 67 57 / 14%);
}
.quiz-progress { display: flex; justify-content: center; gap: 12px; min-height: 22px; }
.quiz-progress span { width: 20px; height: 20px; border: 3px solid var(--blue); border-radius: 50%; background: white; }
.quiz-progress span.is-done { background: var(--blue); }
.quiz-message { margin: auto; color: var(--muted); font-size: 24px; font-weight: 800; text-align: center; }
.quiz-content { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.quiz-question-line { display: flex; align-items: center; justify-content: center; gap: 15px; min-height: 90px; }
.quiz-question-line h2 { margin: 0; font-size: clamp(30px, 4vw, 46px); line-height: 1.12; text-align: center; }
.quiz-audio { flex: 0 0 60px; width: 60px; height: 60px; border: 3px solid var(--blue); border-radius: 50%; background: white; font-size: 27px; }
.quiz-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: center; gap: 15px; flex: 1; min-height: 0; }
.quiz-choices.is-yes-no { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.quiz-choice { min-height: 110px; padding: 13px; border: 4px solid var(--blue); border-radius: 19px; background: white; color: var(--ink); font-size: clamp(27px, 3.4vw, 38px); font-weight: 900; }
.quiz-choice.is-selected { border-color: var(--gold); background: #fff4d9; }
.quiz-choice.is-correct { border-color: var(--green); background: #e4f3e8; }
.quiz-choice.is-wrong { border-color: #af4b42; background: #fae9e5; }
.quiz-parent-check { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.quiz-parent-check p { width: 100%; margin: 2px 0 0; font-size: 19px; font-weight: 800; text-align: center; }
.quiz-feedback { min-height: 28px; margin: 9px 0 4px; color: var(--muted); font-size: 20px; font-weight: 800; text-align: center; }
.quiz-next { align-self: flex-end; }
.quiz-finish { display: grid; flex: 1; place-content: center; justify-items: center; gap: 18px; text-align: center; }
.quiz-finish h2 { margin: 0; font-size: 50px; }
.quiz-finish p { margin: 0; font-size: 24px; }
.quiz-write { align-self: center; }

.history-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
  min-height: 0;
  padding: 15px;
  overflow-y: auto;
  border: 2px solid white;
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgb(69 67 57 / 14%);
  overscroll-behavior: contain;
}
.history-entry {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  min-height: 112px;
  padding: 14px 48px 14px 15px;
  border: 3px solid #c2d0d3;
  border-radius: 16px;
  background: white;
  color: var(--ink);
  text-align: left;
}
.history-date { color: var(--blue-dark); font-size: 19px; font-weight: 900; }
.history-preview { display: -webkit-box; overflow: hidden; font-size: 17px; font-weight: 650; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.history-picture-mark { position: absolute; top: 12px; right: 13px; font-size: 25px; }
.history-empty { grid-column: 1 / -1; align-self: center; margin: 0; padding: 50px; color: var(--muted); font-size: 22px; font-weight: 750; text-align: center; }

.detail-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
  padding: 18px;
  border: 2px solid white;
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgb(69 67 57 / 14%);
}
#detail-text { min-height: 0; margin: 0; padding: 16px; overflow-y: auto; border-radius: 15px; background: white; font-size: clamp(22px, 2.8vw, 31px); font-weight: 650; line-height: 1.45; white-space: pre-wrap; }
.detail-picture-wrap { min-width: 0; min-height: 0; overflow: hidden; border-radius: 16px; background: #f0eadb; }
#detail-picture { display: block; width: 100%; height: 100%; object-fit: contain; }
.detail-card:has(.detail-picture-wrap[hidden]) { grid-template-columns: 1fr; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 4px solid #f2c94c; outline-offset: 3px; }
.rotate-message { display: none; }

@media (max-height: 700px) and (orientation: landscape) {
  .journal-shell { padding-top: max(5px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .practice-header { min-height: 56px; padding-bottom: 6px; }
  .practice-header h1 { font-size: 28px; }
  .editor-card { padding: 12px; }
  .writing-panel h2 { font-size: 26px; }
  .writing-help { margin: 3px 0 7px; font-size: 14px; }
  #journal-text { padding: 11px; font-size: 23px; }
  .journal-message { min-height: 20px; margin: 3px 0; font-size: 14px; }
  .primary-button, .secondary-button { min-height: 48px; }
  .journal-choice { padding: 14px; }
  .journal-quiz-card { padding: 13px; }
  .quiz-question-line { min-height: 70px; }
  .quiz-choice { min-height: 85px; }
  .history-list { padding: 10px; }
  .history-entry { min-height: 94px; padding-top: 10px; padding-bottom: 10px; }
}

@media (max-width: 850px) and (orientation: landscape) {
  .practice-header-actions { gap: 7px; }
  .practice-header .profile-summary { font-size: 13px; }
  .history-button { padding-right: 8px; padding-left: 8px; font-size: 14px; }
  .save-actions { gap: 7px; }
  .primary-button, .secondary-button { min-width: 110px; padding-right: 11px; padding-left: 11px; font-size: 16px; }
}

@media (orientation: portrait) {
  .rotate-message { display: grid; position: fixed; z-index: 100; inset: 0; place-items: center; padding: 28px; background: var(--page); }
  .rotate-card { display: grid; justify-items: center; gap: 14px; max-width: 420px; padding: 32px; border-radius: 24px; background: var(--paper); box-shadow: 0 6px 22px rgb(69 67 57 / 14%); font-size: 20px; text-align: center; }
  .rotate-card strong { font-size: 28px; }
  .rotate-icon { color: var(--blue); font-size: 54px; line-height: 1; }
}

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