:root {
  --color-bg: #F9FAFB;
  --color-surface: #FFFFFF;
  --color-surface-alt: #F3F4F6;
  --color-border: #E5E7EB;
  --color-text: #1C1C1E;
  --color-text-muted: #6B7280;
  --color-accent: #E63946;
  --color-accent-hover: #D02C39;
  
  --color-ad-bg: #F3F4F6;
  --color-ad-border: #D1D5DB;

  --font-sans: 'Inter', 'Noto Sans TC', system-ui, sans-serif;
  --font-serif: 'Noto Serif TC', serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 16px;
  
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.03);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

.serif-text { font-family: var(--font-serif); }

.tool-layout {
  position: relative;
  max-width: 1000px;
  width: 100%;
  margin: 28px auto;
  padding: 0 20px;
}

.tool-content {
  max-width: 600px;
  margin: 0 auto;
}

/* Screens */
.screen {
  display: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.screen.active {
  display: block;
  opacity: 1;
}

/* Header Titles */
.header-titles {
  text-align: center;
  margin-bottom: var(--space-8);
}
.shrine-icon {
  width: 48px; height: 48px;
  color: var(--color-accent);
  margin-bottom: var(--space-2);
}
.main-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: var(--space-2);
}
.subtitle {
  color: var(--color-text-muted);
  font-size: 1.1rem;
}

/* Canvas */
.canvas-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-width: 400px;
  margin: 0 auto var(--space-8);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  touch-action: none;
}
#paintCanvas {
  width: 100%;
  height: 100%;
  display: block;
}
.canvas-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--color-text-muted);
  pointer-events: none;
  font-size: 0.9rem;
  opacity: 1;
  transition: opacity 0.3s;
}

/* Buttons */
.action-buttons {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 12px 24px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn:not(:disabled):hover { transform: translateY(-1px); }
.btn:not(:disabled):active { transform: translateY(0); }

.btn-primary {
  background: var(--color-text);
  color: var(--color-surface);
  border: 1px solid var(--color-text);
}
.btn-primary:not(:disabled):hover {
  background: var(--color-accent);
  border-color: var(--color-accent);
}
.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:not(:disabled):hover {
  border-color: var(--color-text);
  background: var(--color-surface-alt);
}
.btn-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* Result Screen */
.result-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: var(--space-8);
}
.result-image-wrapper {
  width: 160px; height: 160px;
  margin: 0 auto var(--space-6);
  border-radius: 50%;
  overflow: hidden;
  border: 4px solid var(--color-bg);
  box-shadow: var(--shadow-sm);
}
.result-image {
  width: 100%; height: 100%;
  object-fit: cover;
}
.result-rank {
  font-size: 2.5rem;
  color: var(--color-accent);
  margin-bottom: var(--space-4);
  letter-spacing: 0.1em;
}
.result-poem {
  font-size: 1.25rem;
  line-height: 1.8;
  color: var(--color-text);
  white-space: pre-line;
}

/* Ads */
.ad-slot { display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.ad-slot::before { content: attr(data-ad-slot) ' ad'; position: absolute; color: var(--color-text-muted); font-size: 0.75rem; }
.ad-slot.ad-loaded::before { display: none; }
.ad-slot--header  { width: 100%; min-height: 90px; max-width: 728px; margin: 12px auto; background: var(--color-ad-bg); border: 1px dashed var(--color-ad-border); }
.ad-slot--sidebar { width: 100%; min-height: auto; max-width: 200px; display: block; background: transparent; border: none; overflow: visible; }
.ad-slot--footer  { width: 100%; min-height: 90px; max-width: 728px; margin: 12px auto; background: var(--color-ad-bg); border: 1px dashed var(--color-ad-border); }

.tool-sidebar { width: 100%; margin-top: 24px; display: flex; justify-content: center; }

@media (min-width: 1025px) {
  .tool-sidebar {
    position: fixed; right: 20px; top: 50%;
    transform: translateY(-50%);
    width: 200px; margin-top: 0; display: block; z-index: 10;
  }
}

.ad-grid { display: flex; flex-direction: column; gap: 8px; }
.ad-img  { width: 100%; height: 100px; object-fit: cover; display: block; }
.ad-card { display: block; text-decoration: none; color: inherit; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; transition: opacity 0.4s ease; }
.ad-label { padding: 4px 8px; display: flex; flex-direction: column; justify-content: center; }
.ad-title { color: var(--color-text); font-weight: bold; font-size: 0.8rem; }
.ad-source { color: var(--color-text-muted); font-size: 0.65rem; }
.ad-sponsor-label { font-size: 0.75rem; color: var(--color-text-muted); margin-bottom: 8px; text-align: center; }

@media (max-width: 1024px) {
  .ad-slot--header, .ad-slot--footer { min-height: 50px; max-width: 320px; }
  .ad-slot--sidebar { max-width: 100%; }
  .ad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 480px; margin: 0 auto; }
  .ad-img { height: 80px; }
}
@media (max-width: 480px) {
  .ad-grid { grid-template-columns: repeat(2, 1fr); }
  .action-buttons { flex-direction: column; align-items: stretch; }
}
