/**
 * Feelings Wheel Main Stylesheet
 */

/* ========================================
   CSS RESET & BASE
   ======================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

main a {
  color: var(--link-color);
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

main a:hover {
  text-decoration: underline;
}

/* ========================================
   LAYOUT
   ======================================== */

header {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md);
  z-index: 20;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-sm) 0;
  gap: var(--space-sm);
}

footer {
  padding: var(--space-md);
  text-align: center;
}

/* ========================================
   WHEEL CONTAINER
   ======================================== */

#wheel-container {
  width: 100%;
  max-width: min(98vh, 98vw);
  aspect-ratio: 1 / 1;
  position: relative;
  margin: 0 auto;
}

#wheel {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* Prevent scroll while pinch-zooming */
}

/* ========================================
   WEDGE STYLES
   ======================================== */

.wedge {
  cursor: pointer;
  transition: opacity var(--transition-normal) ease;
}

.wedge path {
  stroke: var(--wedge-border);
  stroke-width: 1px;
  fill: hsl(var(--wedge-hue), var(--tier-sat), var(--wedge-l));
  transition: fill var(--transition-normal) ease,
              stroke var(--transition-normal) ease;
}

.wedge:hover path {
  stroke-width: 2px;
}

.wedge:focus {
  outline: none;
}

.wedge:focus path {
  stroke: var(--focus-ring);
  stroke-width: var(--focus-ring-width);
}

.wedge[data-selected="true"] path {
  stroke: var(--focus-ring);
  stroke-width: var(--focus-ring-width);
}

/* All three tiers are always rendered and visible. */
.tier-group {
  transform-origin: center;
}

#tier-1,
#tier-2,
#tier-3 {
  opacity: 1;
}

/* Unselected wedges dim when a selection exists on the wheel. */
#wheel[data-has-selection="true"] .wedge:not([data-selected="true"]) path {
  opacity: 0.55;
}

footer {
  padding: var(--space-md);
  text-align: center;
  color: var(--fg);
  opacity: 0.7;
  font-size: 14px;
}

.footer-sep {
  margin: 0 var(--space-sm);
  opacity: 0.5;
}

.footer-version {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 13px;
}

/* Keyboard-active wedge: whichever wedge currently sits at the
   3 o'clock position gets a visible ring + fill boost. Arrow keys
   spin the wheel; Enter activates this wedge. */
.wedge[data-kb-active="true"] path {
  stroke: var(--focus-ring);
  stroke-width: 3;
  stroke-opacity: 0.9;
}

#wheel[data-has-selection="true"] .wedge[data-kb-active="true"] path {
  opacity: 1 !important;
}

/* Spin interactions */
#wheel {
  touch-action: none;
  cursor: grab;
}

#wheel.spinning {
  cursor: grabbing;
}

/* ========================================
   WEDGE LABELS
   ======================================== */

.wedge-label {
  font-size: clamp(12px, 2vw, 18px);
  font-weight: 500;
  fill: var(--label-text);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  user-select: none;
}

.tier-1 .wedge-label {
  font-size: clamp(14px, 2.5vw, 22px);
  font-weight: 600;
}

.tier-3 .wedge-label {
  font-size: clamp(12px, 1.5vw, 14px);
}

/* On viewports smaller than ~700px the wheel is physically small and
   labels compete for room. Bias the outer ring since that's where the
   user's reading focus lands; shrink the inner ring labels to yield
   that visual weight. */
@media (width <= 700px), (height <= 700px) {
  .tier-3 .wedge-label {
    font-size: clamp(12px, 2.4vmin, 16px);
    font-weight: 600;
  }

  .tier-2 .wedge-label {
    font-size: clamp(10px, 1.8vmin, 12px);
    font-weight: 500;
  }

  .tier-1 .wedge-label {
    font-size: clamp(10px, 2vmin, 14px);
    font-weight: 600;
  }
}

/* ========================================
   BREADCRUMB
   ======================================== */

#breadcrumb {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0;
  background: var(--bg);
  z-index: 10;
}

#breadcrumb:not(:empty) {
  padding: var(--space-sm) var(--space-md);
  position: sticky;
  top: 0;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.breadcrumb-item button {
  background: var(--button-bg);
  color: var(--button-fg);
  border: none;
  padding: var(--space-sm) var(--space-md);
  border-radius: 4px;
  font-size: clamp(14px, 2vw, 16px);
  transition: background-color var(--transition-fast) ease;
}

.breadcrumb-item button:hover {
  background: var(--button-hover-bg);
}

.breadcrumb-separator {
  color: var(--fg);
  opacity: 0.5;
}

/* ========================================
   ZOOM CONTROLS
   ======================================== */

#controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

#controls button {
  background: var(--button-bg);
  color: var(--button-fg);
  border: 1px solid var(--border-color);
  padding: var(--space-sm) var(--space-md);
  border-radius: 4px;
  font-size: 18px;
  min-width: 44px;
  min-height: 44px;
  transition: background-color var(--transition-fast) ease;
}

#controls button:hover {
  background: var(--button-hover-bg);
}

/* ========================================
   ABOUT PAGE
   ======================================== */

main h1 {
  font-size: clamp(28px, 6vw, 48px);
  margin-bottom: var(--space-lg);
  text-align: center;
}

main section {
  max-width: 700px;
  margin: 0 auto var(--space-xl);
  padding: var(--space-lg);
  background: var(--button-bg);
  border-radius: 8px;
}

main h2 {
  font-size: clamp(22px, 4vw, 32px);
  margin-bottom: var(--space-md);
}

main p {
  margin-bottom: var(--space-md);
  line-height: 1.7;
}

main ul {
  margin-left: var(--space-lg);
  margin-bottom: var(--space-md);
}

main li {
  margin-bottom: var(--space-sm);
}

/* ========================================
   OUTCOME PANEL
   ======================================== */

#outcome {
  text-align: center;
  padding: var(--space-lg);
  background: var(--button-bg);
  border-radius: 8px;
  max-width: 600px;
  width: 100%;
}

#outcome h2 {
  font-size: clamp(24px, 5vw, 36px);
  margin-bottom: var(--space-md);
}

#outcome p {
  font-size: clamp(16px, 3vw, 18px);
  margin-bottom: var(--space-lg);
  opacity: 0.9;
}

#copy-link {
  background: var(--button-bg);
  color: var(--button-fg);
  border: 1px solid var(--border-color);
  padding: var(--space-sm) var(--space-lg);
  border-radius: 4px;
  font-size: 16px;
  transition: background-color var(--transition-fast) ease;
}

#copy-link:hover {
  background: var(--button-hover-bg);
}

#copy-link:active {
  transform: scale(0.98);
}

/* ========================================
   JOURNAL PROMPTS
   ======================================== */

#journal-prompt-container {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-color);
}

#journal-prompt {
  font-size: clamp(15px, 2.8vw, 17px);
  font-style: italic;
  opacity: 0.75;
  margin-bottom: var(--space-md);
  line-height: 1.6;
}

#dismiss-prompt {
  background: transparent;
  color: var(--fg);
  border: none;
  padding: var(--space-xs) var(--space-sm);
  border-radius: 4px;
  font-size: 13px;
  opacity: 0.6;
  transition: opacity var(--transition-fast) ease;
}

#dismiss-prompt:hover {
  opacity: 0.9;
  text-decoration: underline;
}

/* ========================================
   THEME TOGGLE
   ======================================== */

#theme-toggle {
  background: var(--button-bg);
  color: var(--button-fg);
  border: 1px solid var(--border-color);
  padding: var(--space-sm);
  border-radius: 4px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-theme {
  font-size: 20px;
}

/* ========================================
   KEYBOARD SHORTCUTS MODAL
   ======================================== */

.shortcuts-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

.shortcuts-modal[hidden] {
  display: none;
}

.shortcuts-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 50%);
  opacity: 0;
  transition: opacity var(--transition-normal) ease;
}

.shortcuts-modal:not([hidden]) .shortcuts-backdrop {
  opacity: 1;
}

.shortcuts-content {
  position: relative;
  background: var(--bg);
  color: var(--fg);
  border-radius: 8px;
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 20%);
  transform: scale(0.95);
  opacity: 0;
  transition: transform var(--transition-normal) ease,
              opacity var(--transition-normal) ease;
}

.shortcuts-modal:not([hidden]) .shortcuts-content {
  transform: scale(1);
  opacity: 1;
}

.shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
}

.shortcuts-header h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.shortcuts-close {
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 28px;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color var(--transition-fast) ease;
}

.shortcuts-close:hover {
  background: var(--button-hover-bg);
}

.shortcuts-body {
  padding: var(--space-lg);
}

.shortcut-group {
  margin-bottom: var(--space-lg);
}

.shortcut-group:last-child {
  margin-bottom: 0;
}

.shortcut-group h3 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
  margin-bottom: var(--space-sm);
}

.shortcut-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
  flex-wrap: wrap;
}

.shortcut-item kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 var(--space-sm);
  background: var(--button-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 10%);
}

.shortcut-item span {
  flex: 1;
  font-size: 15px;
}

/* Skip animation for reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .shortcuts-backdrop,
  .shortcuts-content {
    transition: none;
  }

  .shortcuts-content {
    transform: scale(1);
  }

  .shortcuts-modal:not([hidden]) .shortcuts-backdrop {
    opacity: 1;
  }

  .shortcuts-modal:not([hidden]) .shortcuts-content {
    opacity: 1;
  }
}

/* ========================================
   SECTOR VIEW (Mobile Tier 3 Expansion)
   ======================================== */

/* When Tier 3 is in sector view mode, hide inner tiers to focus
   on the expanded tertiary emotions. We use a class on the parent
   wheel-rotation group since CSS siblings can only select forward. */
#wheel-rotation[data-sector-view="true"] #tier-1,
#wheel-rotation[data-sector-view="true"] #tier-2 {
  opacity: 0;
  pointer-events: none;
}

/* Sector view wedges are larger and more accessible on mobile.
   The transition handles switching between ring and sector modes. */
#tier-3 {
  transition: opacity var(--transition-slow) ease;
}

/* In sector view, boost Tier 3 label size for better readability.
   Since wedges are expanded, labels can be larger without overlap. */
#wheel-rotation[data-sector-view="true"] #tier-3 .wedge-label {
  font-size: clamp(14px, 3.5vmin, 20px);
  font-weight: 600;
}

/* Smooth transition for sector view activation */
@media (width < 768px) {
  #wheel-rotation[data-sector-view="true"] #tier-3 {
    transition: opacity var(--transition-slow) ease;
  }
}

/* ========================================
   REDUCED MOTION
   ======================================== */

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

/* ========================================
   RESPONSIVE
   ======================================== */

@media (width >= 768px) {
  main {
    padding: var(--space-md) 0;
  }

  #wheel-container {
    max-width: min(98vh, 98vw);
  }
}

@media (width >= 1024px) {
  #wheel-container {
    max-width: min(98vh, 98vw);
  }
}
