/* SPDX-License-Identifier: AGPL-3.0-or-later */
:root { --bg: #e6e6e3; --ink: #17181a; --card: rgba(255, 255, 255, .92); --line: rgba(0, 0, 0, .08); --edge: rgba(0, 0, 0, .45); --on: #17181a; --on-ink: #fff; }
body.dark { --bg: #020202; --ink: #f1f0ec; --card: rgba(28, 28, 30, .9); --line: rgba(255, 255, 255, .1); --edge: rgba(255, 255, 255, .4); --on: #f1f0ec; --on-ink: #111; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 13px/1.3 system-ui, "Segoe UI", sans-serif; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; opacity: 0; transition: opacity .6s; }
body.ready #view { opacity: 1; }
#brand { position: fixed; left: calc(20px + env(safe-area-inset-left)); top: calc(18px + env(safe-area-inset-top)); letter-spacing: .5em; font-size: 15px; font-weight: 300; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; }
#loading span { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--ink); animation: spin 1s linear infinite; }
body.ready #loading { display: none; }
#loading.failed { padding: 24px; text-align: center; font-size: 15px; }
#loading.failed span { display: none; }
#notice { position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); max-width: min(520px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 12px; background: var(--card); box-shadow: 0 6px 30px var(--line); font-size: 14px; z-index: 5; }
#notice[hidden], #fps[hidden] { display: none; }
#fps { position: fixed; left: calc(14px + env(safe-area-inset-left)); bottom: calc(14px + env(safe-area-inset-bottom)); font: 12px/1.3 ui-monospace, monospace; opacity: .7; white-space: pre; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

#views, #tools { position: fixed; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 2; }
#views { left: calc(14px + env(safe-area-inset-left)); }
#views button { width: 34px; height: 34px; border-radius: 50%; background: var(--card); box-shadow: 0 2px 10px var(--line); font-size: 11px; }
#tools { right: calc(14px + env(safe-area-inset-right)); padding: 6px; border-radius: 22px; background: var(--card); box-shadow: 0 2px 14px var(--line); }
#tools button { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; }
#config { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: 48px; height: 48px; border-radius: 50%; background: var(--card); box-shadow: 0 2px 14px var(--line); display: grid; place-items: center; }
button.on, #views button.on { background: var(--on); color: var(--on-ink); }

.panel { position: fixed; background: var(--card); border-radius: 16px; box-shadow: 0 6px 30px var(--line); padding: 14px 16px; backdrop-filter: blur(10px); }
.panel[hidden] { display: none !important; }
.panel.side { right: calc(70px + env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); width: 232px; display: grid; gap: 12px; }
.panel.bottom { left: 50%; bottom: calc(78px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100vw - 140px); max-height: calc(100vh - 140px - env(safe-area-inset-bottom)); max-height: calc(100dvh - 140px - env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
.panel h2 { margin: 8px 0 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; opacity: .6; }
.panel h2:first-child { margin-top: 0; }
.panel label { display: grid; grid-template-columns: 1fr auto; gap: 4px; }
.panel input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--ink); }
.panel small { opacity: .6; }
#model-info { font-size: 12px; opacity: .75; margin-top: 8px; max-width: 520px; overflow-wrap: anywhere; }
#model-info:empty { display: none; }
#model-info ul { margin: 4px 0 0; padding-left: 18px; max-height: 7.5em; overflow-y: auto; }
.row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--edge); white-space: nowrap; }
.chip i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--line); }

/* Ring editor: panel on the left, the image shifts right (film offset in main.js) */
.panel.design { left: calc(58px + env(safe-area-inset-left)); top: calc(54px + env(safe-area-inset-top)); bottom: calc(18px + env(safe-area-inset-bottom)); width: 316px; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: 8px; }
.panel.design h2 { margin: 6px 0 0; }
.panel.design .chip { padding: 6px 10px; }
.panel.design input[type=search] { width: 100%; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--edge); background: transparent; color: inherit; font: inherit; }
.panel output { font-variant-numeric: tabular-nums; opacity: .75; }
#gem-list { height: 168px; flex: none; overflow-y: auto; display: grid; gap: 2px; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
#gem-list button { display: grid; grid-template-columns: 14px 1fr; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; text-align: left; }
#gem-list button i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--line); }
#gem-list button small { display: block; font-size: 11px; opacity: .6; }
#gem-list:empty::after { content: 'No stone found'; padding: 6px 8px; opacity: .6; }
#band-editor { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
#band-editor[open] { gap: 8px; }
#band-editor summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
#band-editor:not([open]) > :not(summary) { display: none; }

@media (max-width: 640px) {
	.panel.bottom { left: 58px; right: 64px; transform: none; max-width: none; }
	/* Portrait: panel as a sheet at the bottom above the button bars, the image shifts up */
	.panel.design { left: 8px; right: 8px; width: auto; top: 56%; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 3; }
	body.designing #view { transform: translateY(-22vh); }
	/* at the bottom, otherwise the panel covers the ring and the gizmo in portrait */
	.panel.side { right: calc(64px + env(safe-area-inset-right)); width: min(232px, calc(100vw - 130px)); top: auto; bottom: calc(78px + env(safe-area-inset-bottom)); transform: none; }
	#brand { font-size: 13px; }
}

/* Touch: larger targets */
@media (pointer: coarse) {
	#views button, #tools button { width: 42px; height: 42px; }
	.panel.side { right: calc(78px + env(safe-area-inset-right)); }
}
@media (pointer: coarse) and (max-width: 640px) {
	.panel.side { right: calc(72px + env(safe-area-inset-right)); width: min(232px, calc(100vw - 144px)); }
	.panel.bottom { left: 64px; right: 72px; }
}

button:focus-visible, canvas:focus-visible, input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { #view { transition: none; } #loading span { animation-duration: 3s; } }

#gizmo { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; touch-action: none; overflow: visible; }
#gizmo[hidden] { display: none; }
#gizmo .line { fill: none; stroke: var(--ink); stroke-opacity: .32; stroke-width: 1; }
#gizmo .faint { stroke-opacity: .16; stroke-dasharray: 3 4; }
#gizmo .hit { fill: none; stroke: transparent; stroke-width: 20; pointer-events: stroke; cursor: grab; }
#gizmo .hit.fill { fill: transparent; pointer-events: all; }
#gizmo .dot { fill: #e0a35a; stroke: #fff; stroke-width: 1.5; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .35)); }
#gizmo.dragging .hit { cursor: grabbing; }
