/*
 * styles.css -- MathGraphs web edition.
 *
 * The original was a fixed 480 x 320 landscape iPhone screen. Here the plot
 * takes the space it can get and the controls sit beside it on wide screens,
 * below it on narrow ones.
 */

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-soft: #273449;
  --border: #35455f;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #d9a441;
  --accent-strong: #c8933a;
  --accent-ink: #2b1c04;
  --danger: #fca5a5;
  --danger-bg: #7f1d1d;
  --field: #f8fafc;
  --field-ink: #0f172a;
  --radius: 10px;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* --------------------------------------------------------- site header */

.site-header {
  background: #ffffff;
  border-bottom: 1px solid #e3e9e7;
}

.site-header-in {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #0c2622;
  text-decoration: none;
  font-family: "Poppins", "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.92rem;
  background: linear-gradient(135deg, #0b3d36 0%, #1a1a1a 48%, #d9a441 100%);
  color: rgba(255, 255, 255, 0.94);
  letter-spacing: 0.03em;
  text-shadow:
    -1px -1px 1px rgba(0, 0, 0, 0.55),
    1px 1px 1px rgba(255, 255, 255, 0.4);
}

.brand small {
  display: block;
  font-family: "Segoe UI", sans-serif;
  font-weight: 500;
  font-size: 0.64rem;
  color: #5b6b67;
  letter-spacing: 0.04em;
}

.home-link {
  flex: none;
  background: #121212;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.home-link:hover { background: #000; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ------------------------------------------------------------- header */

.app-header {
  padding: 14px 20px 6px;
}

.app-header h1 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: 24px;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

.tagline em { color: var(--accent); font-style: normal; }

/* ------------------------------------------------------------- layout */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  padding: 10px 20px 16px;
  align-items: start;
}

/* --------------------------------------------------------- plot panel */

.plot-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.plot-frame {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Room around the canvas for the four range boxes. */
  padding: 34px 60px 38px 60px;
  box-shadow: var(--shadow);
}

#board {
  display: block;
  width: 100%;
  /* Tall enough to be useful, short enough to leave the controls visible. */
  height: min(62vh, 560px);
  min-height: 260px;
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
  background: #eef3fb;
}

#board.grabbing { cursor: grabbing; }

/* Range boxes, positioned at the edge they control. */

.range-tag {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-dim);
}

.range-tag input {
  width: 62px;
  padding: 3px 6px;
  font: 12px/1.3 ui-monospace, "Cascadia Mono", Consolas, monospace;
  text-align: center;
  color: var(--field-ink);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.range-tag--ymax { top: 7px; left: 50%; transform: translateX(-50%); }
.range-tag--ymin { bottom: 8px; left: 50%; transform: translateX(-50%); }
.range-tag--xmin { left: 6px; top: 50%; transform: translateY(-50%); flex-direction: column; gap: 3px; }
.range-tag--xmax { right: 6px; top: 50%; transform: translateY(-50%); flex-direction: column; gap: 3px; }

.error-box {
  position: absolute;
  left: 60px;
  right: 60px;
  top: 42px;
  margin: 0;
  padding: 8px 11px;
  font-size: 13px;
  color: #fff;
  background: rgba(153, 27, 27, 0.94);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.error-box[hidden] { display: none; }

.readout {
  position: absolute;
  right: 66px;
  bottom: 44px;
  margin: 0;
  padding: 2px 7px;
  font: 11px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: #334155;
  background: rgba(255, 255, 255, 0.82);
  border-radius: 4px;
  pointer-events: none;
}

/* No chip when there is no coordinate to show. */
.readout:empty { display: none; }

.plot-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tool {
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}

.tool:hover { background: #33445e; }

.hint {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-dim);
}

/* ------------------------------------------------------------ controls */

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.card-title {
  display: block;
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.card-title .muted { color: var(--text-dim); font-weight: 400; }

.card-note {
  margin: 6px 0 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.equation-input,
.calc-expression,
.select,
.calc-vars input {
  width: 100%;
  padding: 8px 10px;
  color: var(--field-ink);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 7px;
  font: 15px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.equation-input { resize: vertical; min-height: 52px; }

.select { font-family: inherit; font-size: 14px; }

.button-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.button-row > .select { flex: 1; min-width: 0; }

button {
  font: inherit;
  cursor: pointer;
}

.primary,
.secondary {
  padding: 8px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
}

.primary {
  flex: 1;
  color: var(--accent-ink);
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
}

.primary:hover { filter: brightness(1.07); }

.secondary {
  color: var(--text);
  background: var(--panel-soft);
  border-color: var(--border);
}

.secondary:hover { background: #33445e; }

.wide { flex: 1; }

/* --------------------------------------------------------- calculator */

.calc-vars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.calc-vars label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-dim);
}

.calc-vars input { text-align: center; padding: 6px 4px; }

.calc-result {
  display: block;
  margin: 8px 0;
  padding: 8px 10px;
  min-height: 36px;
  font: 15px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--accent);
  background: #16202f;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow-wrap: anywhere;
}

.calc-result.is-error { color: var(--danger); }

/* ------------------------------------------------------------- footer */

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px 16px;
  font-size: 12px;
  color: var(--text-dim);
}

.app-footer a { color: var(--text-dim); }

/* ------------------------------------------------------------- dialog */

.dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: 84vh;
  padding: 20px 24px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.dialog::backdrop { background: rgba(2, 6, 23, 0.7); }

.dialog h2 { margin: 0 0 12px; font-size: 19px; }
.dialog h3 { margin: 18px 0 6px; font-size: 14px; color: var(--accent); }
.dialog p { margin: 8px 0; font-size: 14px; }

.dialog code {
  padding: 1px 5px;
  font: 13px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: #16202f;
  border-radius: 4px;
}

.dialog kbd {
  padding: 1px 6px;
  font-size: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
}

ul.plain { margin: 6px 0; padding-left: 20px; font-size: 14px; }
ul.plain li { margin: 4px 0; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.dialog-actions .primary { flex: 0 0 auto; }

/* ------------------------------------------------------- narrow screens */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 10px 12px 16px;
  }

  .plot-frame { padding: 32px 60px 36px; }

  #board { height: min(52vh, 440px); }

  .error-box { left: 60px; right: 60px; }

  .hint { margin-left: 0; width: 100%; }
}

@media (max-width: 520px) {
  .app-header { padding: 10px 14px 4px; }
  .plot-frame { padding: 30px 56px 34px; }
  .range-tag input { width: 46px; font-size: 11px; }
  .error-box { left: 56px; right: 56px; font-size: 12px; }
  .readout { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .tool, .primary, .secondary { transition: background-color 120ms ease, filter 120ms ease; }
}
