:root {
  color-scheme: light;
  --background: #a62e38;
  --background-deep: #741f2c;
  --surface: #fffaf0;
  --ink: #2e2325;
  --muted: #756365;
  --line: rgba(255, 244, 216, 0.26);
  --cream: #fff0be;
  --accent: #e25470;
  --accent-dark: #7a2330;
  --pink: #e46fa7;
  --coral: #f06f59;
  --purple: #5b4bb0;
  --teal: #6cacaa;
  --shadow: 0 26px 64px rgba(49, 5, 13, 0.28);
  --font-rounded: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "Arial Rounded MT Bold", "Yu Gothic", sans-serif;
  font-family: var(--font-rounded);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--background-deep);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--cream);
  background:
    linear-gradient(145deg, transparent 0 72%, rgba(91, 75, 176, 0.62) 72% 84%, transparent 84%) fixed,
    linear-gradient(35deg, transparent 0 78%, rgba(228, 111, 167, 0.72) 78% 91%, transparent 91%) fixed,
    linear-gradient(165deg, #b73540 0%, var(--background) 54%, var(--background-deep) 100%);
}

body.locked { overflow: hidden; }

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.access-gate {
  display: grid;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
  place-items: center;
}

.access-card {
  width: min(100%, 340px);
  padding: 42px 30px 32px;
  border-radius: 22px;
  color: var(--ink);
  background: var(--surface);
  box-shadow:
    9px 10px 0 rgba(240, 111, 89, 0.36),
    -8px 16px 0 rgba(91, 75, 176, 0.26),
    var(--shadow);
  text-align: center;
}

.access-card .eyebrow {
  margin-bottom: 24px;
  color: var(--accent-dark);
}

.access-card h1 {
  margin: 0 0 24px;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
}

.access-code {
  width: 100%;
  min-height: 60px;
  padding: 8px 14px;
  border: 1px solid rgba(122, 35, 48, 0.24);
  border-radius: 14px;
  color: var(--ink);
  background: #fffdf7;
  font: 800 1.7rem/1 var(--font-rounded);
  letter-spacing: 0.42em;
  text-align: center;
}

.access-code::placeholder { color: rgba(117, 99, 101, 0.42); }
.access-code:focus { outline: 3px solid rgba(226, 84, 112, 0.24); outline-offset: 2px; }

.access-error {
  margin: 12px 0 0;
  color: var(--accent-dark);
  font-size: 0.8rem;
}

.access-button {
  width: 100%;
  min-height: 50px;
  margin-top: 20px;
  border: 0;
  border-radius: 14px;
  color: #fff9e8;
  background: linear-gradient(120deg, var(--accent), var(--coral));
  font-weight: 800;
  cursor: pointer;
}

.access-button:active { transform: scale(0.985); }
.access-button:focus-visible { outline: 3px solid rgba(122, 35, 48, 0.32); outline-offset: 3px; }

.app-shell {
  position: relative;
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
}

.app-shell::before,
.app-shell::after {
  position: fixed;
  z-index: -1;
  display: block;
  content: "";
  pointer-events: none;
}

.app-shell::before {
  top: 8%;
  left: -20%;
  width: 62vw;
  max-width: 390px;
  aspect-ratio: 1;
  border-radius: 42% 58% 64% 36% / 52% 42% 58% 48%;
  background: rgba(240, 111, 89, 0.3);
  transform: rotate(-22deg);
}

.app-shell::after {
  right: -24%;
  bottom: -8%;
  width: 68vw;
  max-width: 430px;
  aspect-ratio: 1;
  border-radius: 68% 32% 34% 66% / 42% 58% 42% 58%;
  background: rgba(108, 172, 170, 0.22);
  transform: rotate(18deg);
}

.topbar {
  position: relative;
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: center;
}

.remaining-count {
  margin: 0;
  color: rgba(255, 240, 190, 0.88);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

.back-button {
  position: absolute;
  left: 0;
  min-width: 64px;
  min-height: 44px;
  padding: 0;
  border: 0;
  color: var(--cream);
  background: transparent;
  cursor: pointer;
}

.main-view {
  display: flex;
  min-height: calc(100dvh - 58px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 0 30px;
}

.welcome-panel {
  margin: 0 0 18px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--cream);
  font-family: var(--font-rounded);
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.3em;
}

.card {
  --card-color: var(--pink);
  --card-color-2: var(--coral);
  --card-color-3: var(--purple);
  position: relative;
  display: grid;
  width: min(100%, 352px);
  height: 510px;
  min-height: 510px;
  margin: 6px 0 26px;
  padding: 0 30px 22px;
  grid-template-rows: 140px 82px minmax(0, 1fr) 24px;
  overflow: hidden;
  border: 0;
  border-radius: 18px;
  color: var(--ink);
  background: var(--surface);
  box-shadow:
    9px 10px 0 rgba(240, 111, 89, 0.36),
    -8px 16px 0 rgba(91, 75, 176, 0.26),
    var(--shadow);
  text-align: center;
}

.card::before {
  position: absolute;
  top: -34px;
  left: -12%;
  width: 124%;
  height: 170px;
  border-radius: 0 0 58% 36% / 0 0 58% 34%;
  background: linear-gradient(118deg, var(--card-color) 0 46%, var(--card-color-2) 46% 69%, var(--card-color-3) 69% 100%);
  content: "";
  transform: rotate(-3deg);
}

.card[data-category="ロマンチック"],
.history-item[data-category="ロマンチック"] { --card-color: #e46fa7; --card-color-2: #f08b68; --card-color-3: #674eb0; }
.card[data-category="気持ち"],
.history-item[data-category="気持ち"] { --card-color: #7255b8; --card-color-2: #e476a8; --card-color-3: #679fa8; }
.card[data-category="ドキドキ"],
.history-item[data-category="ドキドキ"] { --card-color: #cf3747; --card-color-2: #f06f59; --card-color-3: #e66f9f; }
.card[data-category="二人の日常"],
.history-item[data-category="二人の日常"] { --card-color: #5e9fa6; --card-color-2: #e56f9f; --card-color-3: #5b4bb0; }
.card[data-category="密着"],
.history-item[data-category="密着"] { --card-color: #9e2938; --card-color-2: #d84d6b; --card-color-3: #6550ae; }

.card-enter { animation: card-enter 360ms ease-out both; }

.card-topline {
  position: relative;
  z-index: 1;
  display: flex;
  height: auto;
  align-items: flex-start;
  justify-content: space-between;
  padding-top: 24px;
  color: #fff9e8;
  text-align: left;
}

.card-number {
  display: flex;
  margin: 0;
  flex-direction: column;
  font-family: var(--font-rounded);
  line-height: 1;
}

.card-number span {
  margin-bottom: 5px;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.card-number strong {
  font-size: 3.25rem;
  font-weight: 900;
  letter-spacing: -0.06em;
}

.card-title {
  position: relative;
  display: grid;
  margin: 0;
  place-items: center;
  font-family: var(--font-rounded);
  font-size: clamp(1.2rem, 5vw, 1.55rem);
  font-weight: 800;
  line-height: 1.45;
  letter-spacing: 0.035em;
  text-wrap: balance;
}

.card-text {
  position: relative;
  min-height: 0;
  margin: 12px 0 0;
  overflow-y: auto;
  color: #4e4744;
  font-size: clamp(0.93rem, 3.7vw, 1.03rem);
  line-height: 1.9;
  text-align: left;
}

.card-wordmark {
  align-self: end;
  margin: 0;
  color: var(--card-color);
  font-family: var(--font-rounded);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.34em;
}

.round-complete {
  margin: -10px 0 12px;
  color: rgba(255, 249, 232, 0.8);
  font-size: 0.86rem;
  line-height: 1.7;
  text-align: center;
}

.round-complete p { margin: 0; }
.round-complete strong { color: var(--cream); font-weight: 700; }

.heart-button {
  position: relative;
  display: grid;
  width: 190px;
  height: 170px;
  flex: 0 0 auto;
  margin: 0 0 10px;
  place-items: center;
  border: 0;
  color: #fff9e8;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 14px 20px rgba(45, 5, 12, 0.28));
  transition: filter 180ms ease, transform 180ms ease;
}

.card:not([hidden]) ~ .heart-button { width: 142px; height: 128px; margin-top: 0; }

.heart-shape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.heart-shape path { fill: url(#heart-gradient); }

.heart-content {
  position: relative;
  display: flex;
  max-width: 125px;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-bottom: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.04em;
}

.heart-mark { font-family: var(--font-rounded); font-size: 1.2rem; line-height: 1; }
.heart-button:active { transform: scale(0.955); filter: drop-shadow(0 7px 12px rgba(45, 5, 12, 0.22)); }
.heart-button:focus-visible { outline: none; }
.heart-button:focus-visible .heart-shape { filter: drop-shadow(0 0 5px rgba(255, 240, 190, 0.9)); }
.danger-button:focus-visible, .back-button:focus-visible, .history-link:focus-visible, .reset-link:focus-visible { outline: 3px solid rgba(255, 240, 190, 0.72); outline-offset: 4px; }

.comfort-note {
  max-width: 430px;
  margin: 2px 0 8px;
  color: rgba(255, 249, 232, 0.72);
  font-size: 0.72rem;
  line-height: 1.7;
  text-align: center;
}

.storage-warning {
  max-width: 430px;
  margin: 2px 0 8px;
  color: var(--cream);
  font-size: 0.76rem;
  line-height: 1.6;
  text-align: center;
}

.history-link {
  min-height: 44px;
  padding: 12px;
  color: var(--cream);
  font-size: 0.8rem;
  text-underline-offset: 4px;
}

.main-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.reset-link {
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  color: rgba(255, 240, 190, 0.78);
  background: transparent;
  font-size: 0.76rem;
  text-decoration: underline;
  text-decoration-color: rgba(255, 240, 190, 0.32);
  text-underline-offset: 4px;
  cursor: pointer;
}

.history-view { padding: 26px 0 48px; }
.history-heading { margin: 0 0 30px; text-align: center; }
.history-heading h1 { margin: 0; color: #fff9e8; font-family: var(--font-rounded); font-size: 2rem; font-weight: 800; letter-spacing: 0.08em; }
.history-list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }

.history-item {
  --card-color: var(--pink);
  position: relative;
  padding: 20px 22px 20px 26px;
  overflow: hidden;
  border: 0;
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.96);
  box-shadow: 0 10px 26px rgba(45, 5, 12, 0.13);
}

.history-item::before { position: absolute; inset: 0 auto 0 0; width: 7px; background: var(--card-color); content: ""; }

.history-date { display: block; margin-bottom: 7px; color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.history-meta { margin: 0 0 7px; color: var(--card-color); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.04em; }
.history-card-title { margin: 0; font-family: var(--font-rounded); font-size: 1.02rem; font-weight: 700; line-height: 1.55; }
.history-card-text { margin: 12px 0 0; color: #4e4744; font-size: 0.86rem; line-height: 1.75; }
.history-empty { margin: 80px 0; color: rgba(255, 249, 232, 0.75); text-align: center; }
.history-actions { display: grid; gap: 10px; margin-top: 40px; padding-top: 28px; border-top: 1px solid var(--line); }

.danger-button {
  min-height: 48px;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
}

.danger-button { border: 0; color: var(--cream); }
.danger-button:disabled { cursor: default; opacity: 0.4; }

.confirm-dialog {
  width: min(calc(100% - 40px), 390px);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 24px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 26px 80px rgba(45, 29, 29, 0.24);
}

.confirm-dialog::backdrop {
  background: rgba(43, 34, 34, 0.38);
  backdrop-filter: blur(3px);
}

.confirm-content { padding: 28px 24px 22px; text-align: center; }
.confirm-content h2 { margin: 0 0 14px; font-family: var(--font-rounded); font-size: 1.3rem; font-weight: 700; letter-spacing: 0.08em; }
.confirm-content p { margin: 0; color: #4e4744; font-size: 0.95rem; line-height: 1.7; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 26px; }
.dialog-cancel-button, .dialog-accept-button { min-height: 48px; border-radius: 13px; cursor: pointer; }
.dialog-cancel-button { border: 1px solid var(--line); color: var(--ink); background: transparent; }
.dialog-accept-button { border: 0; color: #fffaf7; background: var(--accent); }
.dialog-cancel-button:focus-visible, .dialog-accept-button:focus-visible { outline: 3px solid rgba(137, 56, 73, 0.35); outline-offset: 3px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@keyframes card-enter {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (min-width: 700px) {
  .app-shell { padding-inline: 32px; }
  .main-view { padding-block: 34px 46px; }
}

@media (max-height: 760px) {
  .main-view { justify-content: flex-start; }
  .welcome-panel { margin-top: 8vh; }
  .heart-button { width: 160px; height: 144px; margin-top: 2px; }
}

@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; }
}
