:root {
  --c-bg: #fff8e7;
  --c-ink: #2b2b2b;
  --c-ink-soft: #6b6b6b;
  --c-yellow: #ffd54a;
  --c-pink: #ff8fb1;
  --c-cyan: #5ec8e6;
  --c-lime: #a7d948;
  --c-orange: #ff9a4c;
  --c-purple: #b07ae6;
  --c-mint: #6ed1b3;
  --c-red: #f06262;
  --c-card: #ffffff;
  --c-shadow: rgba(40, 40, 40, 0.12);
  --c-overlay: rgba(20, 20, 20, 0.45);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: "Hiragino Maru Gothic ProN", "ヒラギノ丸ゴ ProN", "Rounded Mplus 1c", "M PLUS Rounded 1c", "Yu Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 10% 10%, #ffe9a7 0, transparent 40%),
    radial-gradient(circle at 90% 20%, #ffc6d6 0, transparent 40%),
    radial-gradient(circle at 50% 95%, #cfeaff 0, transparent 45%),
    var(--c-bg);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 32px;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ====== トップバー ====== */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  background: transparent;
}

.topbar-left {
  min-width: 0;
  display: flex;
  align-items: center;
}

.topbar-title {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  color: var(--c-ink);
  letter-spacing: 0.02em;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iconbtn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #ffffff;
  color: var(--c-ink);
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08), 0 2px 8px var(--c-shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.iconbtn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.08), 0 1px 4px var(--c-shadow);
}
.iconbtn[hidden] { display: none; }

.textbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  background: #ffffff;
  color: var(--c-ink);
  font-family: inherit;
  font-weight: 800;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08), 0 2px 8px var(--c-shadow);
  cursor: pointer;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.textbtn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.08), 0 1px 4px var(--c-shadow);
}
.textbtn[hidden] { display: none; }
.textbtn-link {
  background: #2b2b2b;
  color: #fff;
}

/* ====== ホームビュー ====== */
.view { animation: fadeIn 0.25s ease both; }
.view[hidden] { display: none; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero {
  text-align: center;
  padding: 8px 0 16px;
}
.hero-emoji {
  font-size: 56px;
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.12));
}
.hero-title {
  margin: 8px 0 4px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.04em;
}
.hero-sub {
  margin: 0;
  color: var(--c-ink-soft);
  font-size: 14px;
}

.timer-select {
  margin: 12px 0 18px;
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 2px 8px var(--c-shadow);
}
.timer-select-label {
  font-weight: 700;
  font-size: 15px;
}
.timer-select-input {
  font-size: 15px;
  font-family: inherit;
  border: 2px solid #ececec;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-weight: 700;
  color: var(--c-ink);
  min-width: 110px;
}

.theme-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.theme-btn {
  width: 100%;
  min-height: 96px;
  border: none;
  border-radius: var(--radius-lg);
  padding: 14px 10px;
  font-family: inherit;
  font-weight: 800;
  font-size: 16px;
  color: #2b2b2b;
  background: var(--btn-bg, var(--c-yellow));
  box-shadow: 0 6px 0 rgba(0,0,0,0.12), 0 4px 12px var(--c-shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}
.theme-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.12), 0 2px 6px var(--c-shadow);
}
.theme-btn .theme-emoji {
  font-size: 32px;
  line-height: 1;
}
.theme-btn .theme-label {
  display: block;
  font-size: 15px;
}

.theme-btn.full {
  grid-column: 1 / -1;
}

/* じぶんのリスト用タイル + 編集ボタン */
.custom-tile-wrap {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.custom-tile {
  flex: 1;
  min-width: 0;
  background: #ffffff;
  border: 2px dashed #f4c945;
}
.custom-count {
  font-weight: 800;
  color: var(--c-orange);
  font-size: 13px;
  margin-left: 4px;
}
.custom-edit-btn {
  width: 88px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--c-yellow);
  color: var(--c-ink);
  font-family: inherit;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,0.12), 0 4px 12px var(--c-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px;
}
.custom-edit-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.12), 0 2px 6px var(--c-shadow);
}
.custom-edit-btn-emoji {
  font-size: 22px;
  line-height: 1;
}

/* ====== クイズビュー ====== */
.topic-card {
  background: #fff;
  border-radius: 28px;
  padding: 28px 20px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.06), 0 4px 16px var(--c-shadow);
  text-align: center;
  margin: 12px 0 18px;
  border: 4px solid var(--c-yellow);
  position: relative;
  overflow: hidden;
}
.topic-card::before {
  content: "";
  position: absolute;
  inset: -40px;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 213, 74, 0.25) 0 22px, transparent 24px),
    radial-gradient(circle at 85% 15%, rgba(255, 143, 177, 0.25) 0 18px, transparent 20px),
    radial-gradient(circle at 80% 85%, rgba(94, 200, 230, 0.25) 0 20px, transparent 22px),
    radial-gradient(circle at 20% 85%, rgba(167, 217, 72, 0.25) 0 18px, transparent 20px);
  pointer-events: none;
}
.topic-label {
  position: relative;
  font-size: 14px;
  color: var(--c-ink-soft);
  letter-spacing: 0.15em;
  margin-bottom: 12px;
  font-weight: 800;
}
.topic-text {
  position: relative;
  font-size: 40px;
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: 0.05em;
  word-break: break-word;
  color: var(--c-ink);
}
.topic-text.flash {
  animation: pop 0.4s ease;
}
@keyframes pop {
  0% { transform: scale(0.85); opacity: 0; }
  60% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); }
}

/* タイマー */
.timer-area {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 14px;
  text-align: center;
  box-shadow: 0 2px 8px var(--c-shadow);
}
.timer-display {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--c-ink);
  margin-bottom: 8px;
}
.timer-display.warn { color: var(--c-orange); }
.timer-display.danger {
  color: var(--c-red);
  animation: blink 0.8s ease infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.timer-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ボタン */
.btn {
  appearance: none;
  border: none;
  font-family: inherit;
  font-weight: 800;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 16px;
  cursor: pointer;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary {
  background: var(--c-yellow);
  color: var(--c-ink);
  box-shadow: 0 4px 0 rgba(0,0,0,0.12), 0 2px 8px var(--c-shadow);
}
.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.12), 0 1px 4px var(--c-shadow);
}
.btn-sub {
  background: #fff;
  color: var(--c-ink);
  box-shadow: 0 4px 0 rgba(0,0,0,0.08), 0 2px 8px var(--c-shadow);
}
.btn-sub:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.08), 0 1px 4px var(--c-shadow);
}
.btn-reroll {
  width: 100%;
  background: var(--c-pink);
  color: #fff;
  font-size: 18px;
  padding: 14px 18px;
  margin-bottom: 16px;
}

/* 履歴 */
.history {
  background: #ffffffaa;
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.history-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--c-ink-soft);
  margin-bottom: 6px;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-list li {
  font-size: 14px;
  color: var(--c-ink);
  padding: 4px 0;
  border-bottom: 1px dashed #e6e6e6;
}
.history-list li:last-child { border-bottom: none; }

/* ====== モーダル ====== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal[hidden] { display: none; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: var(--c-overlay);
  animation: fadeOverlay 0.2s ease both;
}
@keyframes fadeOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  background: #fff;
  border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0,0,0,0.18);
  animation: slideUp 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  -webkit-overflow-scrolling: touch;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@media (min-width: 481px) {
  .modal { align-items: center; }
  .modal-panel { border-radius: 24px; max-width: 420px; margin: 0 16px; }
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #f1f1f1;
  font-size: 16px;
  cursor: pointer;
}
.modal-title {
  margin: 4px 0 12px;
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}
.modal-text {
  text-align: center;
  color: var(--c-ink-soft);
  margin: 0 0 16px;
  font-size: 14px;
}
.modal-list,
.modal-list-bullet {
  margin: 0 0 14px;
  padding-left: 1.4em;
  line-height: 1.7;
  font-size: 14.5px;
}
.modal-list-bullet { list-style: disc; }
.modal-list li,
.modal-list-bullet li { padding: 2px 0; }

.help-section {
  margin: 18px 0 8px;
  font-size: 15px;
  font-weight: 900;
  color: var(--c-ink);
  border-left: 6px solid var(--c-yellow);
  padding: 2px 0 2px 10px;
  line-height: 1.4;
}
.help-section:first-of-type { margin-top: 6px; }
.help-section-team   { border-left-color: var(--c-pink); }
.help-section-custom { border-left-color: var(--c-cyan); }
.modal-ok { width: 100%; }
.modal-legal-link {
  display: block;
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--c-ink-soft);
  text-decoration: underline;
}
.modal-legal-link:hover { color: var(--c-ink); }
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ====== エディタ（じぶんのリスト編集） ====== */
.modal-panel-tall {
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.editor-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px; /* iOSで自動拡大を防ぐ */
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid #ececec;
  background: #fff;
  color: var(--c-ink);
}
.editor-input:focus {
  outline: none;
  border-color: var(--c-yellow);
}
.editor-add-btn {
  padding: 0 16px;
  flex-shrink: 0;
  min-height: 44px;
}

.editor-status {
  font-size: 13px;
  color: var(--c-orange);
  text-align: center;
  margin: -4px 0 8px;
  font-weight: 800;
}

.editor-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 4px;
  flex: 1;
  min-height: 80px;
  max-height: 50vh;
  overflow-y: auto;
  background: #faf8f3;
  border-radius: var(--radius-sm);
  border: 1px solid #ececec;
}
.editor-list:empty { display: none; }
.editor-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px dashed #e6e6e6;
  font-size: 15px;
}
.editor-list li:last-child { border-bottom: none; }
.editor-item-text {
  flex: 1;
  word-break: break-word;
}
.editor-del-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: var(--c-red);
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0,0,0,0.06);
  flex-shrink: 0;
}
.editor-del-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
}

.editor-empty {
  text-align: center;
  color: var(--c-ink-soft);
  font-size: 13px;
  padding: 18px 8px;
  margin-bottom: 10px;
  background: #faf8f3;
  border-radius: var(--radius-sm);
  border: 1px dashed #ddd;
  line-height: 1.6;
}
.editor-empty[hidden] { display: none; }

.editor-actions {
  margin-top: auto;
}

/* ====== お題一覧 ====== */
.topic-list-btn {
  width: 100%;
  margin-top: 16px;
  background: #ffffff;
}

.topic-list-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px 12px;
  padding: 0 4px 4px;
}

.topic-list-section {
  margin-bottom: 18px;
}
.topic-list-section:last-child {
  margin-bottom: 4px;
}

.topic-list-heading {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 900;
  padding: 2px 0 2px 10px;
  border-left: 6px solid var(--c-yellow);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.topic-list-count {
  font-size: 12px;
  color: var(--c-ink-soft);
  font-weight: 800;
}

.topic-list-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-block;
  padding: 5px 10px;
  background: #faf8f3;
  border: 1px solid #ececec;
  border-radius: 999px;
  font-size: 13px;
  color: var(--c-ink);
  line-height: 1.3;
}
.chip-empty {
  color: var(--c-ink-soft);
  background: transparent;
  border-style: dashed;
}

.topic-list-actions {
  grid-template-columns: 1fr;
  margin-top: 4px;
}
