:root {
  --bg: #061418;
  --bg-2: #0b2026;
  --panel: rgba(8, 28, 34, 0.78);
  --gold: #d3b06a;
  --gold-strong: #efd18f;
  --text: #e9e3cf;
  --muted: #a9b5ac;
  --danger: #e07a5f;
  --bg-image: none;
  --overlay-opacity: 0.78;
  --bg-blur: 0px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--app-font-family, "京华老宋体", "京華老宋体", "STSong", "SimSun", serif);
  background-image: radial-gradient(circle at top, #1f4d5c 0%, var(--bg) 58%),
    linear-gradient(160deg, var(--bg-2) 0%, var(--bg) 100%);
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  background-attachment: fixed, fixed;
  color: var(--text);
  position: relative;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(var(--bg-blur));
  transform: scale(1.05);
  z-index: -2;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(
    rgb(6 20 24 / var(--overlay-opacity)),
    rgb(6 20 24 / calc(var(--overlay-opacity) + 0.12))
  );
  z-index: -1;
}

.app-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 14px calc(92px + env(safe-area-inset-bottom));
}

.app-header {
  text-align: center;
  padding: 14px 10px;
  border: 1px solid rgba(211, 176, 106, 0.38);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(22, 53, 64, 0.68), rgba(9, 23, 29, 0.88));
  box-shadow: 0 0 24px rgba(12, 62, 74, 0.32);
}

.app-header h1 {
  margin: 0;
  font-size: 1.9rem;
  letter-spacing: 0.22rem;
}

.app-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.app-main {
  margin-top: 14px;
}

.page-tab {
  border-radius: 14px;
  padding: 10px 6px;
  font-size: 0.9rem;
}

.page-tab.is-active {
  border-color: rgba(248, 227, 170, 0.95);
  box-shadow: 0 0 0 1px rgba(248, 227, 170, 0.35) inset;
}

.page-section {
  display: none;
  margin-top: 12px;
  gap: 12px;
}

.page-section.is-active {
  display: grid;
}

.bottom-tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(94vw, 700px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border-radius: 16px;
  border: 1px solid rgba(211, 176, 106, 0.35);
  background: rgba(9, 25, 31, 0.88);
  backdrop-filter: blur(10px);
  z-index: 20;
}

.panel {
  padding: 14px;
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid rgba(211, 176, 106, 0.28);
  backdrop-filter: blur(2px);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.task-inputs {
  display: grid;
  gap: 10px;
}

.task-form label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

input {
  width: 100%;
  border: 1px solid rgba(132, 184, 170, 0.45);
  border-radius: 10px;
  background: rgba(4, 20, 24, 0.78);
  color: var(--text);
  padding: 10px 12px;
}

input[type="range"] {
  padding: 0;
  height: 28px;
}

button {
  border: 1px solid rgba(239, 205, 132, 0.7);
  background: linear-gradient(160deg, #3e5f66, #7e6232);
  color: #fff5da;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
}

select {
  width: 100%;
  border: 1px solid rgba(132, 184, 170, 0.45);
  border-radius: 10px;
  background: rgba(4, 20, 24, 0.9);
  color: var(--text);
  padding: 9px 10px;
}

.pool-grid {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.pool-grid h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--gold-strong);
}

.task-list,
.timeline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.task-list li,
.timeline-list li {
  padding: 8px 10px;
  border: 1px solid rgba(134, 188, 173, 0.26);
  border-radius: 10px;
  background: rgba(170, 217, 203, 0.07);
  font-size: 0.92rem;
}

.draw-panel {
  text-align: center;
}

.draw-btn {
  width: 100%;
  border-radius: 999px;
  font-size: 1rem;
  padding: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.draw-btn.shaking {
  animation: shakeTube 0.75s ease-in-out;
}

.draw-icon {
  display: inline-block;
  transform-origin: 50% 80%;
}

.draw-btn.shaking .draw-icon {
  animation: iconSpin 0.75s ease-in-out;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.task-dialog {
  width: min(92vw, 420px);
  border: none;
  padding: 0;
  background: transparent;
}

.task-dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.task-card {
  background: linear-gradient(180deg, #113640 0%, #0a1f28 75%);
  border: 1px solid rgba(239, 205, 132, 0.5);
  border-radius: 16px;
  padding: 16px;
  transform: translateY(18px) scale(0.94);
  opacity: 0;
}

.task-dialog[open] .task-card {
  animation: cardPopIn 0.42s ease forwards;
}

.task-card h2 {
  margin-top: 0;
}

.draw-result p {
  margin: 6px 0;
  color: #f6e8c6;
}

.task-card.reveal .bamboo-stick:nth-child(1) {
  animation: stickRise 0.5s ease forwards;
}

.task-card.reveal .bamboo-stick:nth-child(2) {
  animation: stickRise 0.58s ease 0.08s forwards;
}

.task-card.reveal .bamboo-stick:nth-child(3) {
  animation: stickRise 0.64s ease 0.14s forwards;
}

.task-card.reveal .draw-result {
  animation: fadeInUp 0.45s ease 0.2s both;
}

.timer-wrap {
  margin-top: 10px;
  text-align: center;
  border: 1px dashed rgba(239, 205, 132, 0.5);
  border-radius: 12px;
  padding: 12px;
}

.timer-wrap p {
  margin: 0;
  color: var(--muted);
}

.timer-wrap strong {
  display: block;
  margin: 8px 0 10px;
  font-size: 2rem;
  letter-spacing: 0.08rem;
}

.timer-btn {
  width: 100%;
}

.actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.toolbar label {
  font-size: 0.9rem;
  color: var(--muted);
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#import-file-input {
  display: none;
}

.file-btn {
  border: 1px solid rgba(239, 205, 132, 0.7);
  background: linear-gradient(160deg, #3e5f66, #7e6232);
  color: #fff5da;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  text-align: center;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.inline-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

#font-file-input {
  display: none;
}

.task-badge {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(239, 205, 132, 0.6);
  color: #ffe6b4;
  font-size: 0.75rem;
}

.week-board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(180px, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.week-column {
  border: 1px solid rgba(211, 176, 106, 0.28);
  border-radius: 12px;
  padding: 8px;
  background: rgba(10, 30, 36, 0.42);
}

.week-column h3 {
  margin: 0 0 8px;
  color: var(--gold-strong);
  font-size: 0.9rem;
}

.week-subtitle {
  margin: 6px 0 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.week-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 5px;
}

.week-list li {
  border: 1px solid rgba(134, 188, 173, 0.26);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(170, 217, 203, 0.07);
  font-size: 0.82rem;
}

.week-task {
  cursor: grab;
  user-select: none;
}

.week-task:active {
  cursor: grabbing;
}

.week-task.dragging {
  opacity: 0.45;
  border-style: dashed;
}

.week-task.touch-dragging {
  opacity: 0.5;
  border-style: dashed;
}

.week-list.drop-active {
  outline: 2px dashed rgba(239, 205, 132, 0.7);
  outline-offset: 2px;
  border-radius: 9px;
}

.week-list.touch-drop-target {
  box-shadow: 0 0 0 1px rgba(239, 205, 132, 0.25) inset;
}

.week-list.touch-drop-active {
  outline: 2px dashed rgba(239, 205, 132, 0.85);
  outline-offset: 2px;
  border-radius: 9px;
}

.timeline-group {
  border: 1px solid rgba(214, 179, 106, 0.25);
  border-radius: 10px;
  padding: 8px;
  background: rgba(9, 30, 36, 0.38);
}

.timeline-date {
  margin: 2px 2px 8px;
  font-size: 0.85rem;
  color: var(--gold-strong);
}

.bamboo-wrap {
  display: flex;
  justify-content: center;
  gap: 12px;
  min-height: 92px;
  margin: 6px 0 10px;
}

.bamboo-stick {
  width: 16px;
  height: 86px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f3ddae 0%, #b7924f 100%);
  border: 1px solid rgba(91, 70, 35, 0.45);
  transform: translateY(24px) scaleY(0.2);
  opacity: 0;
}

@keyframes stickRise {
  0% {
    transform: translateY(28px) scaleY(0.2);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scaleY(1);
    opacity: 1;
  }
}

@keyframes shakeTube {
  0%,
  100% {
    transform: translateX(0) rotate(0);
  }
  20% {
    transform: translateX(-3px) rotate(-2deg);
  }
  40% {
    transform: translateX(3px) rotate(2deg);
  }
  60% {
    transform: translateX(-2px) rotate(-1deg);
  }
  80% {
    transform: translateX(2px) rotate(1deg);
  }
}

@keyframes iconSpin {
  0%,
  100% {
    transform: rotate(0);
  }
  50% {
    transform: rotate(14deg);
  }
}

@keyframes fadeInUp {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardPopIn {
  0% {
    transform: translateY(18px) scale(0.94);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.ghost {
  background: rgba(17, 33, 39, 0.82);
  border-color: rgba(224, 122, 95, 0.7);
  color: #ffd2c6;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.top-gap {
  margin-top: 10px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.color-item {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

.color-item input[type="color"] {
  height: 40px;
  padding: 4px;
  border-radius: 10px;
  cursor: pointer;
}

.preset-btn {
  padding: 9px 8px;
  font-size: 0.85rem;
}

.preset-btn.is-active {
  border-color: rgba(248, 227, 170, 0.95);
  box-shadow: 0 0 0 1px rgba(248, 227, 170, 0.35) inset;
}

body[data-theme="xuanqing"] {
  --bg: #030c14;
  --bg-2: #061724;
  --panel: rgba(8, 21, 34, 0.8);
  --text: #dae4eb;
  --muted: #93a6b3;
}

body[data-theme="danmo"] {
  --bg: #121518;
  --bg-2: #252a2e;
  --panel: rgba(32, 35, 38, 0.78);
  --gold: #c4ac7d;
  --gold-strong: #e2cda4;
  --text: #f0ece2;
  --muted: #bab4a5;
}

@media (min-width: 760px) {
  .pool-grid {
    grid-template-columns: 1fr 1fr;
  }

  .tool-grid {
    max-width: 520px;
  }
}

/* 移动端适配 - 安卓手机 */
@media (max-width: 480px) {
  /* 整体布局 - 确保填满屏幕 */
  .app-shell {
    padding: 12px 10px calc(85px + env(safe-area-inset-bottom));
    max-width: 100%;
    width: 100%;
  }

  /* 主内容区填满 */
  .app-main {
    width: 100%;
  }

  /* 面板填满 */
  .page-section.is-active {
    width: 100%;
  }

  .panel {
    width: 100%;
  }

  /* 项目池 - 明确宽度 */
  .pool-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .pool-grid article {
    min-width: 0;
  }

  .pool-grid h3 {
    font-size: 0.82rem;
  }

  /* 月/周选择器缩小 */
  .task-inputs {
    gap: 8px;
    width: 100%;
  }

  .task-form {
    padding: 10px 8px;
    border-radius: 10px;
    width: 100%;
  }

  .task-form label {
    font-size: 0.82rem;
    margin-bottom: 4px;
  }

  .top-gap {
    margin-top: 8px;
  }

  #project-cycle,
  #single-cycle,
  #project-week,
  #single-week {
    padding: 7px 8px;
    font-size: 0.85rem;
  }

  .row.top-gap select {
    padding: 7px 8px;
    font-size: 0.85rem;
  }

  /* 周视图看板 - 更小尺寸 */
  .week-board {
    grid-auto-columns: minmax(110px, 1fr);
    gap: 6px;
    padding-bottom: 6px;
    width: 100%;
  }

  .week-column {
    padding: 6px;
    border-radius: 10px;
    min-width: 0;
  }

  .week-column h3 {
    font-size: 0.78rem;
    margin-bottom: 5px;
    word-break: break-word;
  }

  .week-subtitle {
    font-size: 0.68rem;
    margin: 4px 0 3px;
  }

  .week-list li {
    padding: 4px 5px;
    font-size: 0.75rem;
  }

  /* 头部标题 */
  .app-header {
    padding: 12px 8px;
    border-radius: 12px;
  }

  .app-header h1 {
    font-size: 1.6rem;
    letter-spacing: 0.16rem;
  }

  .app-header p {
    font-size: 0.8rem;
  }

  /* 面板 */
  .panel {
    padding: 12px;
    border-radius: 12px;
  }

  .panel h2 {
    font-size: 1rem;
    margin-bottom: 10px;
  }

  /* 抽签按钮 */
  .draw-btn {
    padding: 14px;
    font-size: 0.95rem;
  }

  /* 输入框和按钮 */
  .row {
    grid-template-columns: 1fr auto;
    gap: 6px;
  }

  input, select {
    padding: 9px 10px;
    font-size: 0.9rem;
  }

  button {
    padding: 9px 10px;
    font-size: 0.9rem;
  }

  /* 周视图看板 - 关键优化 */
  .week-board {
    grid-auto-columns: minmax(140px, 1fr);
    gap: 8px;
  }

  .week-column {
    padding: 6px;
    border-radius: 10px;
  }

  .week-column h3 {
    font-size: 0.82rem;
    margin-bottom: 6px;
  }

  .week-subtitle {
    font-size: 0.72rem;
  }

  .week-list li {
    padding: 5px 6px;
    font-size: 0.78rem;
  }

  /* 预设风格按钮 - 改为2列 */
  .preset-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .preset-btn {
    padding: 8px 6px;
    font-size: 0.8rem;
  }

  /* 颜色选择器 */
  .palette-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .color-item {
    font-size: 0.82rem;
  }

  .color-item input[type="color"] {
    height: 36px;
  }

  /* 工具网格 */
  .tool-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  /* 对话框 */
  .task-dialog {
    width: 94vw;
  }

  .task-card {
    padding: 14px;
    border-radius: 14px;
  }

  .task-card h2 {
    font-size: 1rem;
  }

  .timer-wrap {
    padding: 10px;
  }

  .timer-wrap strong {
    font-size: 1.7rem;
  }

  .actions {
    gap: 6px;
  }

  /* 竹签动画 */
  .bamboo-stick {
    width: 14px;
    height: 76px;
  }

  .bamboo-wrap {
    min-height: 80px;
    gap: 10px;
  }

  /* 底部导航 */
  .bottom-tabbar {
    width: 94vw;
    gap: 6px;
    padding: 6px;
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .page-tab {
    padding: 8px 4px;
    font-size: 0.85rem;
  }

  /* 任务列表 */
  .task-list li,
  .timeline-list li {
    padding: 7px 9px;
    font-size: 0.88rem;
  }

  /* 行内复选框 */
  .inline-check {
    font-size: 0.8rem;
    flex-wrap: wrap;
  }

  /* 标签徽章 */
  .task-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    margin-right: 6px;
  }
}

/* 超小屏幕适配 (320px左右) */
@media (max-width: 360px) {
  .app-shell {
    padding: 10px 8px calc(80px + env(safe-area-inset-bottom));
  }

  .app-header h1 {
    font-size: 1.4rem;
    letter-spacing: 0.12rem;
  }

  /* 项目池 - 超小屏改为单列 */
  .pool-grid {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .week-board {
    grid-auto-columns: minmax(100px, 1fr);
  }

  .week-column h3 {
    font-size: 0.72rem;
  }

  .week-list li {
    font-size: 0.7rem;
    padding: 3px 4px;
  }

  .task-form {
    padding: 8px 6px;
  }

  .row {
    grid-template-columns: 1fr auto;
    gap: 5px;
  }

  input, select {
    padding: 8px 8px;
    font-size: 0.85rem;
  }

  button {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .preset-grid {
    grid-template-columns: 1fr 1fr;
  }

  .palette-grid {
    grid-template-columns: 1fr;
  }

  .tool-grid {
    grid-template-columns: 1fr;
  }

  .bamboo-stick {
    width: 12px;
    height: 66px;
  }

  .timer-wrap strong {
    font-size: 1.5rem;
  }
}
