@font-face {
  font-family: "DotGothic16";
  src: url("./assets/DotGothic16-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --theme: #db3329;
  --theme-soft: rgba(219, 51, 41, 0.13);
  --bg: #f5ebd6;
  --surface: rgba(255, 255, 255, 0.74);
  --surface-strong: rgba(255, 255, 255, 0.92);
  --ink: #30251f;
  --muted: rgba(48, 37, 31, 0.62);
  --line: rgba(48, 37, 31, 0.14);
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(48, 37, 31, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "DotGothic16", system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  letter-spacing: 0;
}

body.standard-font {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

img {
  max-width: 100%;
}

.app-shell {
  min-height: 100dvh;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.18) 1px, transparent 1px) 0 0 / 26px 26px,
    linear-gradient(rgba(255,255,255,0.16) 1px, transparent 1px) 0 0 / 26px 26px,
    var(--bg);
}

.loading-screen,
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.loading-screen {
  text-align: center;
  color: var(--muted);
}

.loading-mascot {
  width: 84px;
  image-rendering: pixelated;
}

.login-card {
  width: min(100%, 360px);
  display: grid;
  gap: 18px;
  justify-items: center;
  text-align: center;
}

.mascot {
  width: 132px;
  image-rendering: pixelated;
}

.logo {
  width: 168px;
  image-rendering: pixelated;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
}

.google-signin-wrap {
  min-height: 44px;
  display: grid;
  place-items: center;
}

.fallback-login {
  display: inline-flex;
}

body.gis-ready .fallback-login {
  display: none;
}

.auth-status {
  min-height: 20px;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn,
.icon-btn {
  min-height: 42px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.primary-btn {
  background: var(--theme);
  color: #fff;
  box-shadow: 0 6px 18px rgba(219, 51, 41, 0.24);
}

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

.ghost-btn {
  background: transparent;
  color: var(--theme);
}

.danger-btn {
  background: rgba(180, 35, 24, 0.10);
  color: var(--danger);
  border: 1px solid rgba(180, 35, 24, 0.22);
}

.icon-btn {
  width: 42px;
  padding: 0;
  background: var(--surface-strong);
  color: var(--ink);
  border: 1px solid var(--line);
}

.primary-btn:active,
.secondary-btn:active,
.ghost-btn:active,
.danger-btn:active,
.icon-btn:active {
  transform: scale(0.98);
}

.primary-btn:disabled,
.secondary-btn:disabled,
.danger-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.app-layout {
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 14px calc(148px + env(safe-area-inset-bottom));
}

.top-bar {
  max-width: 680px;
  margin: 0 auto 10px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-logo img:first-child {
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
}

.top-logo img:last-child {
  width: 108px;
  image-rendering: pixelated;
}

.screen {
  max-width: 680px;
  margin: 0 auto;
}

.page-header {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.period-control {
  max-width: 680px;
  margin: 0 auto 10px;
  padding: 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.period-control button {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.period-control button.active {
  background: var(--theme);
  color: #fff;
  box-shadow: 0 4px 12px rgba(48, 37, 31, 0.12);
}

.card,
.record-row,
.setting-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chart-card {
  padding: 14px;
}

.chart-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.chart-title-row h2,
.section-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.4;
}

.pager {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pager button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}

.chart-wrap {
  position: relative;
  height: 288px;
}

canvas {
  width: 100%;
  height: 100%;
}

.empty {
  min-height: 240px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  line-height: 1.7;
}

.selected-record {
  margin-top: 10px;
  padding: 10px;
  border-radius: 6px;
  background: var(--theme-soft);
  display: flex;
  gap: 10px;
  align-items: center;
}

.thumb {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: #fff;
  object-fit: cover;
  border: 1px solid var(--line);
}

.thumb-placeholder {
  display: grid;
  place-items: center;
  color: var(--theme);
  font-size: 22px;
}

.selected-record button {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  color: var(--ink);
  padding: 0;
}

.selected-record h3,
.record-row h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 2px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 14px;
}

.stat {
  min-height: 76px;
  border-radius: 8px;
  padding: 10px 8px;
  background: var(--theme-soft);
  border: 1px solid color-mix(in srgb, var(--theme), transparent 78%);
  display: grid;
  align-content: center;
  text-align: center;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  margin-top: 4px;
  color: var(--theme);
  font-size: 19px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.record-list {
  display: grid;
  gap: 8px;
}

.record-row {
  width: 100%;
  padding: 10px;
  display: flex;
  gap: 10px;
  text-align: left;
  color: var(--ink);
}

.record-row .body {
  flex: 1;
  min-width: 0;
}

.memo {
  margin: 6px 0 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.88);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
  display: flex;
  justify-content: center;
  gap: 10px;
  z-index: 20;
}

.ad-slot {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(69px + env(safe-area-inset-bottom));
  min-height: 58px;
  padding: 3px 16px 5px;
  background: color-mix(in srgb, var(--bg), white 16%);
  display: grid;
  place-items: center;
  z-index: 19;
  pointer-events: none;
}

.ad-slot span {
  width: min(320px, calc(100vw - 32px));
  height: 50px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px dashed rgba(48, 37, 31, 0.32);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 12px;
}

.tab-btn {
  width: min(42vw, 160px);
  min-height: 52px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 5px;
}

.tab-btn.active {
  background: var(--theme-soft);
  color: var(--theme);
}

.tab-icon {
  font-size: 22px;
  line-height: 1;
}

.tab-label {
  font-size: 12px;
}

.settings {
  display: grid;
  gap: 20px;
  padding-bottom: 20px;
}

.setting-block {
  padding: 12px;
}

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

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

.swatch {
  min-height: 42px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.swatch .dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(48, 37, 31, 0.2);
}

.swatch.active {
  outline: 2px solid var(--theme);
}

.setting-actions {
  display: grid;
  gap: 8px;
}

.toggle-row,
.info-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toggle-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--theme);
}

.form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

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

.fortune-chip {
  min-height: 38px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
  color: var(--ink);
}

.fortune-chip.active {
  background: var(--theme);
  color: #fff;
}

.preview-image {
  display: none;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.preview-image.visible {
  display: block;
}

.sheet-backdrop,
.dialog-backdrop,
.photo-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 16, 0.42);
  z-index: 40;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92dvh;
  overflow: auto;
  background: var(--bg);
  border-radius: 8px 8px 0 0;
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.18);
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  z-index: 41;
}

.sheet-head {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 18px;
}

.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(calc(100vw - 40px), 340px);
  background: #fff;
  border-radius: 8px;
  padding: 18px;
  z-index: 50;
  box-shadow: var(--shadow);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.dialog p {
  margin: 0 0 16px;
  line-height: 1.7;
  color: var(--muted);
  white-space: pre-wrap;
}

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

.photo-view {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
}

.photo-view img {
  max-width: 100%;
  max-height: 78dvh;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
}

.photo-close {
  position: fixed;
  right: 18px;
  top: calc(18px + env(safe-area-inset-top));
  z-index: 61;
}

.hidden {
  display: none !important;
}

@media (min-width: 720px) {
  .app-layout {
    padding-top: 18px;
  }

  .chart-wrap {
    height: 340px;
  }

  .sheet {
    left: 50%;
    right: auto;
    bottom: 18px;
    transform: translateX(-50%);
    width: min(520px, calc(100vw - 28px));
    border-radius: 8px;
    padding-bottom: 20px;
  }
}
