/* ============================================================
   N1社説リーダー — N1試験問題用紙風デザイン
   ============================================================ */

:root {
  --paper:       #f5f1e8;   /* 試験問題用紙の薄クリーム */
  --paper-deep:  #ece6d3;   /* やや濃い紙色（線・影） */
  --ink:         #1a1a1a;   /* 本文インク色 */
  --ink-soft:    #4a4a4a;   /* 補助テキスト */
  --ink-light:   #888;
  --rule:        #2a2a2a;   /* 罫線 */
  --accent:      #8b1a1a;   /* 朱色（試験番号・印） */
  --highlight:   #fff7d6;
  --shadow:      rgba(0,0,0,0.08);

  --serif: 'Noto Serif JP', 'YuMincho', '游明朝', 'Hiragino Mincho ProN', serif;
  --sans:  'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

/* ====== 画面切替 ====== */
.screen { display: none; min-height: 100dvh; }
.screen.active { display: block; }

/* ============================================================
   ユーザー選択画面
   ============================================================ */
#screen-user {
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
}
#screen-user.active { display: flex; }

.user-select-wrap {
  width: 100%; max-width: 420px;
  text-align: center;
}

.brand {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 64px;
  letter-spacing: 0.05em;
  color: var(--ink);
  margin: 0 0 4px;
  line-height: 1;
}
.brand-sub {
  font-size: 22px;
  margin-left: 12px;
  color: var(--ink-soft);
}
.brand-desc {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0 0 48px;
  letter-spacing: 0.1em;
}

.user-prompt {
  font-family: var(--serif);
  font-size: 18px;
  margin: 0 0 20px;
  color: var(--ink);
}

.user-buttons {
  display: flex; flex-direction: column; gap: 12px;
}

.user-btn {
  font-family: var(--serif);
  font-size: 20px;
  padding: 18px 24px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.user-btn:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

/* ============================================================
   トップバー
   ============================================================ */
.topbar {
  display: flex; align-items: center;
  padding: 12px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--paper-deep);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title {
  flex: 1; margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  text-align: center;
}
.topbar-read {
  background: rgba(245, 241, 232, 0.95);
  backdrop-filter: blur(8px);
}
.icon-btn {
  background: transparent;
  border: none;
  padding: 8px;
  color: var(--ink);
  cursor: pointer;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--paper-deep); }

.timer-display {
  flex: 1;
  text-align: center;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 20px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.05em;
}

/* ============================================================
   一覧画面
   ============================================================ */
.user-bar {
  padding: 8px 16px;
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--paper-deep);
  background: rgba(255,255,255,0.4);
}
.user-bar strong {
  color: var(--accent);
  font-weight: 500;
}

.shasetsu-list {
  list-style: none;
  margin: 0; padding: 12px;
}
.shasetsu-item {
  background: #fff;
  border: 1px solid var(--paper-deep);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s;
}
.shasetsu-item:active { transform: scale(0.98); }
.shasetsu-item.read::before {
  content: '読了';
  position: absolute;
  top: 8px; right: 8px;
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 2px 6px;
  border-radius: 2px;
  font-family: var(--serif);
}
.item-date {
  font-size: 12px;
  color: var(--ink-light);
  font-family: var(--sans);
  margin-bottom: 6px;
}
.item-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 8px;
  line-height: 1.5;
}
.item-theme {
  display: inline-block;
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--paper);
  padding: 2px 8px;
  border-radius: 10px;
  font-family: var(--sans);
}
.item-chars {
  font-size: 11px;
  color: var(--ink-light);
  margin-left: 8px;
}

.list-empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--ink-soft);
}

.primary-btn {
  font-family: var(--serif);
  font-size: 16px;
  padding: 12px 28px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 2px;
  cursor: pointer;
}
.primary-btn:active { background: #000; }

.ghost-btn {
  font-family: var(--serif);
  font-size: 15px;
  padding: 10px 22px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}
.ghost-btn:active { background: var(--paper-deep); }

/* ============================================================
   読書画面 — N1試験問題用紙風
   ============================================================ */
#screen-read.active {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.exam-paper {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--paper);
  position: relative;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 「問題◯　次の文章を読んで...」 */
.exam-instruction {
  font-family: var(--serif);
  font-size: 14px;
  color: var(--ink);
  padding: 12px 20px 8px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  letter-spacing: 0.05em;
}
.exam-q-num {
  font-weight: 700;
  margin-right: 4px;
}
#exam-q-num-val {
  font-weight: 700;
  margin-right: 16px;
}
.exam-direction {
  font-size: 14px;
}

/* 縦書きエリア — flexbox残り高さを自動で使う */
.vertical-text {
  writing-mode: vertical-rl;
  -ms-writing-mode: tb-rl;
  -webkit-writing-mode: vertical-rl;

  font-family: var(--serif);
  color: var(--ink);
  line-height: 1.9;
  letter-spacing: 0.05em;
  font-size: 18px;
  font-weight: 400;

  /* 試験問題用紙風の余白 */
  padding: 24px 20px 24px 20px;

  /* 親 .exam-paper (flex column) の残り高さを全部使う */
  flex: 1 1 auto;
  min-height: 0;

  /* 縦書きを横スクロール可能に */
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;

  /* 紙のテクスチャ（うっすら） */
  background:
    linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.015) 100%),
    var(--paper);

  /* 句読点を行頭にしない */
  word-break: keep-all;
  line-break: strict;
}

.vertical-text::-webkit-scrollbar { height: 6px; }
.vertical-text::-webkit-scrollbar-track { background: var(--paper-deep); }
.vertical-text::-webkit-scrollbar-thumb { background: var(--ink-light); border-radius: 3px; }

.article-title {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 700;
  margin: 0 24px 0 0;
  padding: 0;
  letter-spacing: 0.1em;
  line-height: 1.6;
}

.article-meta {
  font-family: var(--serif);
  font-size: 12px;
  color: var(--ink-soft);
  margin: 0 24px 0 0;
  padding: 0;
}

.article-content {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 2.0;
  letter-spacing: 0.05em;
  text-indent: 1em; /* 段落字下げ */
}
.article-content p {
  margin: 0;
  text-indent: 1em;
}
.article-content p + p {
  margin-top: 0;
}

/* ページ番号フッター */
.exam-footer {
  border-top: 1px solid var(--rule);
  padding: 6px 0;
  text-align: center;
  font-family: var(--serif);
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--paper);
}

/* 読書画面のアクションボタン */
.read-actions {
  display: flex;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--paper-deep);
}
.read-actions button { flex: 1; }

/* ============================================================
   モーダル
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 100;
}
.modal[hidden] { display: none; }

.modal-content {
  background: var(--paper);
  border: 2px solid var(--rule);
  border-radius: 4px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  font-family: var(--serif);
}
.modal-content-wide { max-width: 480px; }
.modal-content h3 {
  margin: 0 0 20px;
  font-size: 20px;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.05em;
}

.result-time {
  text-align: center;
  margin: 16px 0 20px;
}
.result-label {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.result-value {
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 36px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.05em;
}

.result-stats {
  display: flex;
  justify-content: space-around;
  padding: 12px 0;
  border-top: 1px solid var(--paper-deep);
  border-bottom: 1px solid var(--paper-deep);
  margin-bottom: 12px;
}
.result-stats > div {
  text-align: center;
  font-size: 18px;
  font-weight: 500;
}
.result-note {
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
  margin: 8px 0 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* 履歴リスト */
.history-list {
  list-style: none;
  margin: 0 0 16px; padding: 0;
  max-height: 50vh;
  overflow-y: auto;
}
.history-list li {
  padding: 12px 4px;
  border-bottom: 1px solid var(--paper-deep);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.history-list .h-title {
  flex: 1;
  margin-right: 12px;
  color: var(--ink);
}
.history-list .h-time {
  font-family: 'SF Mono', 'Consolas', monospace;
  color: var(--ink-soft);
  font-size: 13px;
}
.history-list .h-date {
  display: block;
  font-size: 11px;
  color: var(--ink-light);
  margin-bottom: 2px;
}

/* ============================================================
   レスポンシブ
   ============================================================ */
@media (min-width: 768px) {
  .vertical-text {
    font-size: 19px;
    padding: 40px 32px;
  }
  .article-content { font-size: 19px; }
  .article-title { font-size: 28px; }
}

/* タブレット以上では一覧を中央寄せ */
@media (min-width: 600px) {
  .shasetsu-list, .topbar, .user-bar {
    max-width: 720px;
    margin-left: auto; margin-right: auto;
  }
  .topbar { padding-left: 24px; padding-right: 24px; }
}

/* タイマー実行中 */
.timer-display.running {
  color: var(--accent);
}
