/* style.css — I Ching coin toss app */

:root {
  color-scheme: dark;
  --gold: #d7b95c;
  --gold-strong: #f0d27b;
  --gold-muted: #cdb46f;
  --wood: #1a0f08;
  --wood-deep: #120904;
  --wood-soft: #25150b;
  --parchment: #f4e7ca;
  --parchment-muted: #d8c9a7;
  --ink: #2a1a08;
  --red: #d85a50;
  --red-light: #ff9185;
  --line: rgb(215 185 92 / 28%);
  --line-strong: rgb(240 210 123 / 58%);
  --serif: Georgia, "Times New Roman", serif;
  --sans: "Avenir Next", Avenir, "Helvetica Neue", Arial, sans-serif;
}

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

html {
  min-width: 320px;
  background: var(--wood-deep);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--parchment);
  background:
    radial-gradient(circle at 16% 15%, rgb(112 70 26 / 16%), transparent 34rem),
    linear-gradient(145deg, var(--wood) 0%, var(--wood-deep) 78%);
  font-family: var(--serif);
  line-height: 1.55;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button,
textarea,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
textarea:focus-visible,
a:focus-visible,
[tabindex="-1"]:focus-visible {
  outline: 3px solid var(--gold-strong);
  outline-offset: 4px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.is-hidden {
  display: none !important;
}

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

.skip-link {
  position: fixed;
  z-index: 200;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.65rem 1rem;
  color: var(--ink);
  background: var(--parchment);
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 0.86rem;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-180%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  min-height: 100vh;
  min-height: 100svh;
  padding: clamp(1.5rem, 7vw, 4rem);
  overflow-y: auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background:
    radial-gradient(circle at 50% 35%, rgb(88 52 21 / 25%), transparent 30rem),
    rgb(18 9 4 / 98%);
  transition: opacity 400ms ease;
}

.overlay.is-leaving {
  pointer-events: none;
  opacity: 0;
}

.flavor-quote {
  max-width: 43rem;
  margin: 0;
  text-align: center;
}

#flavor-text {
  margin: 0;
  color: var(--parchment);
  font-size: clamp(1rem, 2.2vw, 1.25rem);
  font-style: italic;
  line-height: 1.75;
}

#flavor-source {
  margin-top: 1rem;
  color: var(--gold-muted);
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.start-button,
.query-button,
.toss-button,
.action-button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  border: 1px solid var(--line-strong);
  color: var(--parchment);
  background: rgb(255 255 255 / 3%);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition:
    color 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.start-button {
  min-width: 10rem;
  margin-top: 1.25rem;
  padding: 0.8rem 1.7rem;
  color: var(--wood-deep);
  background: var(--gold-strong);
  animation: quiet-pulse 2.8s ease-in-out infinite;
}

@keyframes quiet-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgb(240 210 123 / 0%);
  }
  50% {
    box-shadow: 0 0 0 0.45rem rgb(240 210 123 / 12%);
  }
}

.start-button:hover,
.query-button:hover,
.toss-button:hover:not(:disabled),
.action-button:hover:not(:disabled) {
  color: var(--wood-deep);
  background: var(--gold-strong);
  border-color: var(--gold-strong);
}

.start-button:hover {
  transform: translateY(-1px);
}

.query-overlay h2 {
  max-width: 32rem;
  margin: 0;
  color: var(--parchment);
  font-size: clamp(1.35rem, 4vw, 2rem);
  font-weight: 400;
  text-align: center;
}

#query-input {
  width: min(100%, 32rem);
  min-height: 7rem;
  padding: 0.9rem 1rem;
  resize: vertical;
  color: var(--parchment);
  background: rgb(255 255 255 / 4%);
  border: 1px solid var(--line-strong);
  border-radius: 0;
  caret-color: var(--gold-strong);
  font-size: 1rem;
  line-height: 1.6;
}

#query-input::placeholder {
  color: #bfae89;
  font-style: italic;
}

.input-help,
.privacy-note {
  width: min(100%, 32rem);
  margin: 0;
  color: var(--parchment-muted);
  font-family: var(--sans);
  font-size: 0.79rem;
  text-align: center;
}

.input-help {
  margin-top: -0.65rem;
}

.privacy-note {
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.query-actions {
  display: flex;
  width: min(100%, 32rem);
  gap: 0.75rem;
  justify-content: center;
}

.query-button {
  flex: 1;
  padding: 0.75rem 1rem;
}

.query-button.secondary {
  color: var(--parchment-muted);
  border-color: var(--line);
}

#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 23rem);
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
}

#board-panel {
  display: flex;
  min-width: 0;
  min-height: 100vh;
  min-height: 100svh;
  flex-direction: column;
  background: var(--wood);
  border-right: 1px solid var(--line);
}

#coin-canvas {
  display: block;
  width: 100%;
  min-height: 20rem;
  flex: 1 1 auto;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
}

#board-panel[data-state="idle"] #coin-canvas,
#board-panel[data-state="holding"] #coin-canvas {
  touch-action: none;
}

#board-panel[data-state="holding"] #coin-canvas {
  cursor: grabbing;
}

#status-bar {
  display: grid;
  min-height: 6.25rem;
  padding: 0.85rem clamp(1rem, 3vw, 2rem);
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  background: rgb(0 0 0 / 36%);
  border-top: 1px solid var(--line);
}

#status-text {
  min-height: 1.6em;
  margin: 0;
  color: var(--parchment-muted);
  font-family: var(--sans);
  font-size: 0.84rem;
  letter-spacing: 0.035em;
}

.toss-button {
  min-width: min(15rem, 42vw);
  padding: 0.75rem 1.1rem;
  color: var(--wood-deep);
  background: var(--gold-strong);
}

#hexagram-panel {
  position: sticky;
  top: 0;
  display: flex;
  min-width: 0;
  height: 100vh;
  height: 100svh;
  flex-direction: column;
  background: rgb(8 4 2 / 42%);
}

#line-display {
  display: flex;
  min-height: 4rem;
  padding: 1rem 1.25rem;
  margin: 0;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 0.25rem;
  list-style: none;
  border-bottom: 1px solid var(--line);
}

.hex-line {
  display: flex;
  padding: 0.18rem 0;
  gap: 0.85rem;
  align-items: baseline;
  animation: line-appear 400ms ease;
}

@keyframes line-appear {
  from {
    opacity: 0;
    transform: translateY(-0.4rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.line-glyph {
  color: var(--parchment);
  font-family: "Courier New", monospace;
  font-size: 0.9rem;
  letter-spacing: 1px;
  white-space: nowrap;
}

.hex-line.changing .line-glyph {
  color: var(--red-light);
}

.line-meta {
  color: var(--gold-muted);
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.reading-display {
  min-height: 0;
  padding: 1.1rem 1.25rem 2rem;
  overflow-y: auto;
  flex: 1 1 auto;
  scrollbar-color: rgb(215 185 92 / 45%) transparent;
  scrollbar-width: thin;
}

.reading-display::-webkit-scrollbar {
  width: 0.35rem;
}

.reading-display::-webkit-scrollbar-track {
  background: transparent;
}

.reading-display::-webkit-scrollbar-thumb {
  background: rgb(215 185 92 / 45%);
  border-radius: 999px;
}

.reading-section {
  padding-bottom: 1.2rem;
  margin-bottom: 1.2rem;
  border-bottom: 1px solid var(--line);
  animation: reading-appear 500ms ease;
}

.reading-section:last-child {
  border-bottom: 0;
}

@keyframes reading-appear {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hex-number,
.hex-name,
.hex-english,
.reading-label,
.reading-text,
.changing-line-text {
  margin-top: 0;
}

.hex-number {
  margin-bottom: 0.25rem;
  color: var(--gold-muted);
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hex-number.small {
  font-size: 0.68rem;
}

.hex-name {
  margin-bottom: 0.15rem;
  color: var(--gold-strong);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.03em;
  line-height: 1.2;
}

.hex-romanized {
  margin-left: 0.35rem;
  color: var(--gold-muted);
  font-size: 0.92rem;
}

.hex-english {
  margin-bottom: 0.9rem;
  color: var(--parchment-muted);
  font-size: 0.88rem;
  font-style: italic;
}

.reading-label {
  margin-bottom: 0.35rem;
  color: var(--gold-muted);
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.reading-text {
  color: var(--parchment);
  font-size: 0.9rem;
  font-style: italic;
  line-height: 1.7;
}

.reading-question {
  border-bottom-color: var(--line);
}

.question-text {
  color: var(--parchment-muted);
  font-style: normal;
  overflow-wrap: anywhere;
}

.changing-label {
  color: var(--red-light);
}

.changing-line-entry {
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.8rem;
  background: rgb(216 90 80 / 10%);
  border-left: 3px solid var(--red-light);
}

.changing-line-num,
.changing-line-dir {
  font-family: var(--sans);
  font-size: 0.72rem;
}

.changing-line-num {
  display: inline-block;
  margin-right: 0.55rem;
  color: var(--red-light);
  font-weight: 700;
}

.changing-line-dir {
  color: var(--parchment-muted);
}

.changing-line-text {
  margin-bottom: 0;
  margin-top: 0.35rem;
  color: var(--parchment);
  font-size: 0.86rem;
  font-style: italic;
  line-height: 1.65;
}

.relating-section {
  opacity: 0.94;
}

.relating-judgment {
  font-size: 0.86rem;
}

.error {
  color: var(--red-light);
}

#action-bar {
  display: flex;
  padding: 0.85rem 1.25rem;
  gap: 0.75rem;
  flex: 0 0 auto;
  background: rgb(18 9 4 / 96%);
  border-top: 1px solid var(--line);
}

.action-button {
  padding: 0.7rem 0.8rem;
  flex: 1;
}

.reflection-disclosure {
  padding: 0.75rem 1.25rem;
  margin: 0;
  color: var(--parchment-muted);
  background: rgb(18 9 4 / 96%);
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.72rem;
  line-height: 1.5;
}

.clipboard-fallback {
  position: fixed;
  top: 0;
  left: -200vw;
  width: 1px;
  height: 1px;
  opacity: 0;
}

@media (max-width: 760px) {
  #app {
    display: flex;
    min-height: 100svh;
    flex-direction: column;
  }

  #board-panel {
    min-height: max(30rem, 68svh);
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #coin-canvas {
    min-height: 20rem;
  }

  #status-bar {
    grid-template-columns: 1fr;
  }

  .toss-button {
    width: 100%;
    min-width: 0;
  }

  #hexagram-panel {
    position: static;
    width: 100%;
    height: auto;
    min-height: 32rem;
  }

  .reading-display {
    overflow-y: visible;
  }

  .reflection-disclosure {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

@media (max-width: 520px) {
  .overlay {
    padding: 1.25rem;
  }

  .query-actions {
    flex-direction: column;
  }

  #board-panel {
    min-height: max(28rem, 72svh);
  }

  #line-display,
  .reading-display,
  #action-bar,
  .reflection-disclosure {
    padding-right: 1rem;
    padding-left: 1rem;
  }

  .hex-line {
    gap: 0.5rem;
  }

  .line-glyph {
    font-size: 0.82rem;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  .overlay {
    justify-content: flex-start;
  }

  #board-panel {
    min-height: 28rem;
  }

  #coin-canvas {
    min-height: 19rem;
  }
}

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

  .start-button {
    animation: none;
  }
}

@media (forced-colors: active) {
  .start-button,
  .query-button,
  .toss-button,
  .action-button {
    border: 2px solid ButtonText;
  }
}
