/* Geschichten-Würfel — eigenes Design
   Palette: Verspielt Lila #9333ea + Gelb + Türkis, märchenhaft-bunt */

:root {
  --purple: #9333ea;
  --purple-dark: #6d28d9;
  --purple-soft: #f3e8ff;
  --yellow: #fbbf24;
  --teal: #14b8a6;
  --teal-soft: #ccfbf1;
  --pink: #ec4899;

  --bg: #faf5ff;
  --bg-grad-1: #f5edff;
  --bg-grad-2: #e0f7f4;
  --surface: #ffffff;
  --surface-2: #faf5ff;
  --text: #2e1065;
  --text-soft: #6b5b95;
  --border: #e9d5ff;
  --shadow: 0 8px 24px rgba(147, 51, 234, 0.14);
  --shadow-sm: 0 3px 10px rgba(147, 51, 234, 0.12);
  --focus: #14b8a6;
  --danger: #e11d48;
  --radius: 18px;
  --radius-lg: 26px;
}

[data-theme="dark"] {
  --purple: #c084fc;
  --purple-dark: #a855f7;
  --purple-soft: #2a1a47;
  --yellow: #fcd34d;
  --teal: #2dd4bf;
  --teal-soft: #134e4a;
  --pink: #f472b6;

  --bg: #1a1030;
  --bg-grad-1: #1e1238;
  --bg-grad-2: #14262b;
  --surface: #251945;
  --surface-2: #2e2052;
  --text: #f3e8ff;
  --text-soft: #c4b5e0;
  --border: #3d2a66;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.4);
  --focus: #2dd4bf;
  --danger: #fb7185;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: "Comic Sans MS", "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 10%, var(--bg-grad-1), transparent 55%),
    radial-gradient(circle at 88% 90%, var(--bg-grad-2), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--purple);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 12px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon {
  font-size: 2.2rem;
  filter: drop-shadow(0 3px 4px rgba(147, 51, 234, 0.35));
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-5px) rotate(6deg); }
}
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: clamp(1.3rem, 5vw, 1.9rem);
  background: linear-gradient(90deg, var(--purple), var(--pink), var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.5px;
}
.tagline {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-soft);
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  font-size: 1.3rem;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}
.icon-btn:hover { transform: scale(1.08); border-color: var(--purple); }
.icon-btn:active { transform: scale(0.95); }

/* Layout */
.app-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 4px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

/* Controls */
.controls { display: flex; flex-direction: column; gap: 16px; }
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.control-label {
  font-weight: 700;
  font-size: 1.05rem;
}
.count-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.count-btn {
  min-width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.count-btn:hover { transform: translateY(-2px); border-color: var(--purple); }
.count-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}

.roll-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 18px;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  background: linear-gradient(135deg, var(--purple), var(--pink) 55%, var(--teal));
  background-size: 200% 200%;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, filter 0.2s ease;
  letter-spacing: 0.5px;
}
.roll-btn:hover { filter: brightness(1.06); transform: translateY(-2px); }
.roll-btn:active { transform: translateY(1px) scale(0.99); }
.roll-emoji { font-size: 1.8rem; display: inline-block; }
.roll-btn.is-rolling .roll-emoji { animation: spin 0.6s linear; }
@keyframes spin {
  from { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(360deg) scale(1.3); }
  to { transform: rotate(720deg) scale(1); }
}

/* Dice grid */
.dice-panel { display: flex; flex-direction: column; gap: 14px; }
.dice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}
.die {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  animation: pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.die.cat-held { border-color: var(--purple); }
.die.cat-ort { border-color: var(--teal); }
.die.cat-gegenstand { border-color: var(--yellow); }
.die.cat-problem { border-color: var(--pink); }
.die.cat-stimmung { border-color: var(--purple-dark); }

@keyframes pop {
  from { opacity: 0; transform: scale(0.4) rotate(-12deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}
.die-cat {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-soft);
}
.die-emoji {
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  line-height: 1;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,0.15));
}
.die-word {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
}

.empty-hint {
  color: var(--text-soft);
  text-align: center;
  margin: 6px 0;
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

/* Write panel */
.write-panel { display: flex; flex-direction: column; gap: 12px; }
.write-head, .saved-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.write-head h2, .saved-head h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--purple-dark);
}
.char-count { font-size: 0.82rem; color: var(--text-soft); }
textarea {
  width: 100%;
  resize: vertical;
  min-height: 120px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: inherit;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--surface-2);
}
textarea::placeholder { color: var(--text-soft); opacity: 0.8; }

.write-actions, .modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button { font-family: inherit; }

.primary-btn, .ghost-btn, .danger-btn {
  flex: 1 1 auto;
  min-height: 50px;
  padding: 12px 16px;
  font-size: 1.02rem;
  font-weight: 700;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease, background 0.2s ease;
  overflow-wrap: anywhere;
}
.primary-btn {
  border: none;
  color: #fff;
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  box-shadow: var(--shadow-sm);
}
.primary-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.ghost-btn {
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.ghost-btn:hover { border-color: var(--purple); transform: translateY(-1px); }
.danger-btn {
  border: none;
  color: #fff;
  background: var(--danger);
}
.danger-btn:hover { filter: brightness(1.08); }

/* Saved list */
.saved-panel { display: flex; flex-direction: column; gap: 12px; }
.badge {
  background: var(--teal);
  color: #062f2c;
  font-weight: 800;
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 0.9rem;
  min-width: 28px;
  text-align: center;
}
[data-theme="dark"] .badge { color: #d2fff8; }
.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.saved-item {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.saved-item-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.saved-emojis { font-size: 1.5rem; letter-spacing: 2px; overflow-wrap: anywhere; }
.saved-date { font-size: 0.78rem; color: var(--text-soft); }
.saved-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}
.saved-item-actions { display: flex; justify-content: flex-end; }
.del-btn {
  border: 2px solid var(--border);
  background: transparent;
  color: var(--danger);
  border-radius: 12px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.92rem;
}
.del-btn:hover { background: var(--danger); color: #fff; border-color: transparent; }

/* Footer */
.app-footer {
  text-align: center;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  color: var(--text-soft);
  font-size: 0.88rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--purple-dark);
  color: #fff;
  padding: 13px 22px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(46, 16, 101, 0.5);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 95;
}
.modal {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.modal h3 { margin: 0 0 8px; color: var(--purple-dark); }
.modal p { margin: 0 0 18px; color: var(--text-soft); }

/* Fokus-States */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (max-width: 420px) {
  .control-row { justify-content: center; }
  .control-label { width: 100%; text-align: center; }
  .count-picker { justify-content: center; width: 100%; }
}
