:root {
  --ink: #24322f;
  --muted: #66736f;
  --paper: #fffaf0;
  --paper-line: #eadfcb;
  --panel: #ffffff;
  --accent: #2f7d73;
  --accent-dark: #24645d;
  --accent-soft: #dff2ee;
  --warning: #b4533b;
  --warning-soft: #fbe7df;
  --shadow: 0 18px 45px rgba(53, 75, 70, 0.12);
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background:
    linear-gradient(rgba(234, 223, 203, 0.55) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 30px;
  line-height: 1.6;
}

button, input { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.app {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

header {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}

h1, h2, h3, p { margin: 0; }

h1 {
  font-size: clamp(2rem, 6vw, 3.9rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.subtitle {
  color: var(--muted);
  font-size: 1rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin: 24px 0;
}

.stat-card, .form-panel, .book-card, .empty-state, .chart-panel, .license-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(85, 112, 105, 0.16);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card { padding: 16px; }

.stat-label {
  color: var(--muted);
  font-size: 0.84rem;
}

.stat-value {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.1rem, 2.4vw, 1.8rem);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.small-note {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

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

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #2f7d73, #b58b42);
  transition: width 180ms ease;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(260px, 0.85fr);
  gap: 18px;
  margin-bottom: 22px;
}

.chart-panel, .license-panel {
  padding: 18px;
}

.chart-wrap {
  height: 260px;
  margin-top: 12px;
  border: 1px solid rgba(85, 112, 105, 0.12);
  border-radius: 7px;
  background: #fffefa;
  padding: 12px;
}

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

.prediction-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.prediction-list strong { color: var(--ink); }

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.form-panel {
  padding: 20px;
  position: sticky;
  top: 16px;
}

.section-title {
  font-size: 1.15rem;
  margin-bottom: 14px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cfd9d4;
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fffefa;
}

input:focus {
  outline: 3px solid rgba(47, 125, 115, 0.18);
  border-color: var(--accent);
}

.primary-btn, .secondary-btn, .danger-btn, .utility-btn {
  min-height: 42px;
  border-radius: 7px;
  padding: 9px 13px;
  font-weight: 800;
}

.primary-btn { color: #fff; background: var(--accent); }
.primary-btn:hover { background: var(--accent-dark); }
.secondary-btn { color: var(--accent-dark); background: var(--accent-soft); }
.danger-btn { color: var(--warning); background: var(--warning-soft); }
.utility-btn { color: var(--ink); background: #f2eadc; }

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.error {
  min-height: 1.4em;
  color: var(--warning);
  font-size: 0.86rem;
  font-weight: 700;
}

.books { display: grid; gap: 16px; }
.book-card { padding: 18px; }

.book-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.book-title {
  font-size: 1.35rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.author {
  color: var(--muted);
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.metric {
  min-width: 0;
  border: 1px solid rgba(85, 112, 105, 0.14);
  border-radius: 7px;
  padding: 10px;
  background: #fffefa;
}

.metric small {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.record-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed #ccd7d2;
}

.history { margin-top: 14px; }

.history-title {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  margin-bottom: 8px;
}

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

.history-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 7px;
  background: #f8f5ed;
}

.history-main {
  min-width: 0;
  overflow-wrap: anywhere;
}

.history-meta {
  color: var(--muted);
  font-size: 0.83rem;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.license-panel {
  margin-top: 22px;
  color: var(--muted);
  font-size: 0.9rem;
}

.license-panel strong { color: var(--ink); }

@media (max-width: 1060px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .dashboard { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .layout { grid-template-columns: 1fr; }
  .form-panel { position: static; }
}

@media (max-width: 620px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding-top: 22px;
  }

  .stats, .metric-grid, .button-row { grid-template-columns: 1fr; }

  .book-head, .record-form, .history-row { grid-template-columns: 1fr; }

  .book-head { display: grid; }
  .history-row { gap: 4px; }
  .chart-wrap { height: 220px; }
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-panel {
  width: min(360px, 100%);
  padding: 28px;
}

.login-panel h1 {
  font-size: 1.6rem;
  margin-bottom: 8px;
}
