:root {
  /* Doraemon 配色 */
  --dora-blue: #009eff;
  --dora-red: #e92024;
  --dora-white: #ffffff;
  --dora-bell: #ffd500;
  --dora-text: #333333;
  --dora-bg: #f0f8ff;
  --ring-bg: #e4f2ff;
}

/* Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

.huninn-regular {
  font-family: "Huninn", sans-serif;
  font-weight: 400;
  font-style: normal;
}

body {
   font-family: 'Huninn', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    system-ui, sans-serif;
  background-color: var(--dora-bg);
  /* 方格紙背景 */
  background-image:
    linear-gradient(#e0e0e0 1px, transparent 1px),
    linear-gradient(90deg, #e0e0e0 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--dora-text);
  min-height: 100vh;
  padding-bottom: 40px;
}

/* 手繪風盒子 */
.hand-drawn-box {
  border: 3px solid var(--dora-text);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.15);
}

/* Loading */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--dora-blue);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.loading-icon {
  font-size: 4rem;
  animation: spin 2s infinite linear;
}

.loading-text {
  color: var(--dora-white);
  font-weight: 900;
  margin-top: 16px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Header */
.header {
  max-width: 720px;
  margin: 10px auto 0;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.header-date {
  font-size: 0.9rem;
  color: #555;
}

.header-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--dora-blue);
  text-align: center;
  text-shadow: 2px 2px 0 var(--dora-white), -1px -1px 0 var(--dora-text);
}

/* Layout */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 900;
  margin-bottom: 10px;
  color: var(--dora-text);
}

/* Timer section */
.timer-section {
  margin-top: 8px;
  padding: 16px;
  background: var(--dora-white);
}

.mode-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.mode-button {
  flex: 1 1 30%;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-weight: 800;
  border-radius: 999px;
  border: 2px solid var(--dora-text);
  background: var(--dora-bell);
  color: var(--dora-text);
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}

.mode-button:hover {
  transform: translateY(-1px);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.15);
}

.mode-button.active {
  background: var(--dora-red);
  color: var(--dora-white);
}

.timer-display {
  text-align: center;
  margin: 12px 0;
}

.timer-mode-label {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 4px;
}

.timer-clock {
  font-family: 'JetBrains Mono', 'SF Mono', ui-monospace, monospace;
  font-size: 2rem;
  font-weight: 900;
  color: var(--dora-blue);
  text-shadow: 2px 2px 0 var(--dora-white), -1px -1px 0 var(--dora-text);
}

.timer-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.primary-button,
.secondary-button {
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid var(--dora-text);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.12);
  background: var(--dora-white);
  color: var(--dora-text);
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}

.primary-button {
  background: var(--dora-blue);
  color: var(--dora-white);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.15);
}

/* Icon button (for download backup) */
.icon-button {
  padding: 6px 10px;
  border-radius: 999px;
  border: 2px solid var(--dora-text);
  font-size: 1.2rem;
  cursor: pointer;
  background: var(--dora-white);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
}

.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.15);
  background: #f5f5f5;
}

.icon-button:active {
  transform: translateY(0);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.12);
}

/* Rings section */
.rings-section {
  margin-top: 16px;
  padding: 16px;
  background: var(--dora-white);
}

.rings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .rings-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.ring-card {
  padding: 12px;
  background: var(--ring-bg);
  border-radius: 24px;
  border: 3px solid var(--dora-text);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.12);
}

.ring-title {
  font-size: 1rem;
  font-weight: 900;
  text-align: center;
  margin-bottom: 6px;
}

.ring-visual {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 6px 0;
}

.ring-circle {
  position: relative;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background:
    conic-gradient(var(--ring-color) var(--ring-percent), #e5e5e5 0deg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-circle-inner {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--dora-white);
  border: 2px solid var(--dora-text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-percent-text {
  font-size: 1rem;
  font-weight: 900;
  color: var(--dora-text);
}

.ring-info {
  text-align: center;
  margin-top: 4px;
}

.ring-text {
  font-size: 0.9rem;
  font-weight: 700;
}

/* 今日摘要 */
.today-summary-section {
  margin-top: 16px;
  padding: 16px;
  background: var(--dora-white);
}

.today-numbers {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.today-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.today-note {
  margin-bottom: 10px;
}

.today-note label {
  display: block;
  font-size: 0.85rem;
  margin-top: 10px;
  margin-bottom: 4px;
}

#todayNote {
  width: 100%;
  min-height: 72px;
  padding: 8px;
  border-radius: 12px;
  border: 2px solid var(--dora-text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.today-manual-time {
  margin-top: 12px;
  border-top: 1px dashed #ddd;
  padding-top: 10px;
}

.manual-time-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.85rem;
}

.manual-time-label {
  min-width: 90px;
}

/* 手機版：起訖時間同一排、按鈕獨立一排，整體不超出寬度 */
@media (max-width: 600px) {
  .today-manual-time {
    padding-inline: 12px;
  }

  .manual-time-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
  }

  /* 第一行：標籤 + 起訖時間一排 */
  .manual-time-row .manual-time-top {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
  }

  .manual-time-label {
    min-width: auto;
    text-align: center; /* 項目文字置中對齊 */
    font-weight: 700;
  }

  .manual-time-row input[type='time'] {
    flex: 1;
    min-width: 0;           /* 防止撐出容器 */
  }

  /* 第二行：按鈕獨立一排吃滿寬度 */
  .manual-time-row .secondary-button {
    width: 100%;
    box-sizing: border-box;
    justify-content: center;
    text-align: center;
  }
}


/* 歷史紀錄 */
.history-section {
  margin-top: 16px;
  padding: 16px;
  background: var(--dora-white);
}

/* 最近修煉記錄：七天小圈圈列 */
.history-list {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: flex-end;
  overflow-x: hidden;   /* 關閉 X 軸捲動，讓內容強制縮進一行 */
  padding-top: 8px;
}

/* 每一天的小卡片：改用彈性寬度，平均分成七格 */
.history-day {
  flex: 1 1 calc((100% - 6 * 8px) / 7); /* 7 個項目，中間 6 個 gap */
  max-width: calc((100% - 6 * 8px) / 7);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 日期文字 */
.history-day-date {
  font-size: 0.7rem;
  margin-bottom: 4px;
  color: #666;
}

/* 三合一同心圓容器 */
.history-rings {
  position: relative;
  width: 40px;
  height: 40px;
}

/* 外圈 / 中圈 / 內圈半徑設定 */
.history-ring-outer,
.history-ring-middle,
.history-ring-inner {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  background: conic-gradient(var(--ring-color) var(--ring-percent), #e5e5e5 0deg);
}

/* 外圈：最大 */
.history-ring-outer {
  width: 40px;
  height: 40px;
}

/* 中圈：略小 */
.history-ring-middle {
  width: 30px;
  height: 30px;
}

/* 內圈：最小 */
.history-ring-inner {
  width: 20px;
  height: 20px;
}

/* 中心空白圓，讓圈圈看起來更像指標 */
.history-ring-center {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--dora-white);
  border: 1px solid #ccc;
}

/* 三個模式的顏色沿用原本設定 */
.history-ring-outer {
  --ring-color: #ff5b5b; /* coding */
}

.history-ring-middle {
  --ring-color: #3ac48b; /* reading */
}

.history-ring-inner {
  --ring-color: #ffb347; /* writing */
}

/* 各模式顏色 */
.ring-coding {
  --ring-color: #ff5b5b;
}

.ring-reading {
  --ring-color: #3ac48b;
}

.ring-writing {
  --ring-color: #ffb347;
}

.bar-coding {
  background: #ff5b5b;
}

.bar-reading {
  background: #3ac48b;
}

.bar-writing {
  background: #ffb347;
}

.toast {
  position: fixed;
  left: 50%;
  top: 12%;              /* 大螢幕：上方中間 */
  transform: translateX(-50%);
  max-width: 320px;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  background: #016fad;    /* Doraemon 深藍 */
  color: #fff;
  z-index: 1000;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  display: none;          /* 由 showToast 控制 block/none */
  text-align: center;
}

/* 顯示時加一個 class（如果你想做動畫用） */
/* .toast--visible {
  opacity: 1;
  transform: translateY(0);
} */

@media (max-width: 600px) {
  .toast {
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);  /* 留左右邊距 */
    max-width: 360px;
  }
}

.total-progress {
  margin: 6px 0 4px;
}

.total-progress-bar {
  position: relative;
  width: 100%;
  height: 25px;
  border-radius: 999px;
  border: 2px solid var(--dora-text);
  overflow: hidden;
  background: #f5f5f5;
  margin-bottom: 4px;
  display: flex;               /* 讓三段橫向排開 */
}

.total-progress-segment {
  height: 100%;
}

/* 三個顏色 */
.total-progress-segment.bar-coding {
  background: #ff5b5b;
}

.total-progress-segment.bar-reading {
  background: #3ac48b;
}

.total-progress-segment.bar-writing {
  background: #ffb347;
}

/* 中央的文字 */
.total-progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.total-progress-label span {
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4); /* 或 rgba(255,255,255,0.6) 視覺風格擇一 */
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

/* Modal 遮罩層 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

/* Modal 卡片 */
.modal-card {
  position: relative;
  max-width: 500px;
  width: calc(100% - 32px);
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  background: var(--dora-white);
  animation: modalSlideUp 0.3s ease-out;
}

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

.modal-card-top-right {
  position: absolute;
  top: 10px;
  right: 12px;
  display: flex;
  gap: 6px;
  align-items: center;
}

/* 關閉按鈕 */
.modal-close {
  position: relative;
  top: 0;
  right: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--dora-text);
  background: var(--dora-red);
  color: var(--dora-white);
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}

.modal-close:hover {
  transform: scale(1.1);
}

/* 卡片導航按鈕 */
.day-card-nav {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  margin-top: 16px;
}

.day-card-nav .secondary-button {
  flex: 1;
}

.day-card-nav .secondary-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === 當日卡片：同心圓 + 文字 === */

.day-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-right: 40px; /* 預留給右上角的關閉按鈕空間 */
}

.day-card-header-left {
  display: flex;
  flex-direction: column;
}

.day-card-date {
  font-size: 1rem;
  font-weight: 900;
  color: var(--dora-blue);
}

/* 行事曆切換按鈕：沿用鈴鐺黃 對齊關閉鈕高度，但在卡片內容區內，略往左 */
.day-card-calendar-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--dora-text);
  background: var(--dora-bell);
  color: var(--dora-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.12);
}

.day-card-subtitle {
  font-size: 0.8rem;
  color: var(--dora-text);
  margin-top: 2px;
}

.day-card-main {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

/* 左側大同心圓，參考歷史小圈圈放大版 */
.day-card-rings {
  position: relative;
  width: 120px;
  height: 120px;
}

.day-card-rings-outer,
.day-card-rings-middle,
.day-card-rings-inner {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  background: conic-gradient(
    var(--ring-color) var(--ring-percent),
    #e5e5e5 0deg
  );
}


/* 外圈：Coding */
.day-card-rings-outer {
  width: 120px;
  height: 120px;
  --ring-color: #ff5b5b;
}

/* 中圈：Reading */
.day-card-rings-middle {
  width: 92px;
  height: 92px;
  --ring-color: #3ac48b;
}

/* 內圈：Writing */
.day-card-rings-inner {
  width: 64px;
  height: 64px;
  --ring-color: #ffb347;
}

/* 中心空白圓 */
.day-card-rings-center {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--dora-white);
  border: 1px solid #ccc;
}

/* 右側文字區 */
.day-card-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day-card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.9rem;
}

.day-card-label {
  font-weight: 800;
}

.day-card-row-coding .day-card-label {
  color: #ff5b5b;
}

.day-card-row-reading .day-card-label {
  color: #3ac48b;
}

.day-card-row-writing .day-card-label {
  color: #ffb347;
}

.day-card-value {
  font-weight: 700;
  color: var(--dora-text);
}

/* 當日筆記區塊 */
.day-card-note {
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid #444;
  background: var(--dora-blue);
}

.day-card-note-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--dora-bell);
  margin-bottom: 4px;
}

.day-card-note-body {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--dora-white);
  white-space: pre-wrap;
}

/* 手機版：上下堆疊 */
@media (max-width: 600px) {
  .day-card-main {
    flex-direction: column;
    align-items: center;
  }

  .day-card-text {
    width: 100%;
  }
}

/* === 月檢視 === */

.month-view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.month-view-title {
  font-weight: 900;
  font-size: 1rem;
  color: var(--dora-blue);
  text-align: center;
  flex: 1;
}

.month-view-nav {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  margin-top: 12px;
}

.month-view-nav .secondary-button {
  flex: 1;
}

/* 星期列 */
.month-week-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
  font-size: 0.7rem;
  text-align: center;
  color: #666;
}

/* 日期格子區塊 */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

/* 每一格日期 */
.month-cell {
  position: relative;
  padding: 4px 0 6px;
  border-radius: 12px;
  cursor: pointer;
  min-height: 44px;
  background: #f5f9ff;
  border: 1px solid #ddd;
  transition: transform 0.05s, box-shadow 0.05s;
}

.month-cell:hover {
  transform: translateY(-1px);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.12);
}

/* 非本月日期：灰一點 */
.month-cell-outside {
  opacity: 0.35;
}

/* 日期數字 */
.month-cell-day {
  font-size: 0.7rem;
  text-align: center;
  margin-bottom: 2px;
  color: var(--dora-text);
}

/* 中間的小同心圓：延伸歷史圈圈風格 */
.month-cell-rings {
  position: relative;
  width: 28px;
  height: 28px;
  margin: 0 auto;
}

.month-ring-outer,
.month-ring-middle,
.month-ring-inner {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
}

.month-ring-outer {
  width: 28px;
  height: 28px;
}

.month-ring-middle {
  width: 22px;
  height: 22px;
}

.month-ring-inner {
  width: 16px;
  height: 16px;
}

.month-ring-center {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dora-white);
  border: 1px solid #ccc;
}

/* 月檢視左上角返回日檢視按鈕（用同一顆樣式） */
#monthBackToDay {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--dora-text);
  background: var(--dora-blue);
  color: var(--dora-white);
  font-size: 0.9rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 手機：字縮小、格子更緊 */
@media (max-width: 600px) {
  .month-week-row {
    font-size: 0.65rem;
  }

  .month-cell-day {
    font-size: 0.65rem;
  }
}