:root {
  --washi: #f2efe7;
  --sumi: #2a2927;
  --muted: #8c877d;
  --hairline: rgba(42, 41, 39, 0.12);
  --shu: #b8432f;
  --kin: #c99a3e;
}

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  background: var(--washi);
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  font: 500 15px/1.2 "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
  letter-spacing: 0.04em;
  color: var(--sumi);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#table {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#table canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#height {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

#height[hidden] { display: none; }

#bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  column-gap: 28px;
  min-height: 53px;
  padding: 4px max(16px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-top: 1px solid var(--hairline);
}

.row {
  display: flex;
  align-items: center;
}

/* What the bar shows at each stage. */
.choose, .status, #save, #count, #progress { display: none; }
[data-mode="ready"] .choose { display: flex; }
[data-mode="joining"] .status, [data-mode="gilding"] .status, [data-mode="finishing"] .status { display: flex; }
[data-mode="joining"] #count { display: block; }
[data-mode="gilding"] #progress, [data-mode="finishing"] #progress { display: block; }
[data-mode="done"] #save { display: block; }

button, .sheet-actions a {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  letter-spacing: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s;
}

.actions button, .sheet-actions button, .sheet-actions a { color: var(--sumi); }

.vessels button[aria-checked="true"] { color: var(--sumi); }

.vessels button[aria-checked="true"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: var(--kin);
}

.seal, .sheet-actions .seal {
  flex: 0 0 auto;
  min-height: 34px;
  margin-left: 6px;
  padding: 0 12px;
  border: 1px solid var(--shu);
  border-radius: 2px;
  color: var(--shu);
}

.glazes { gap: 4px; }

.glazes button {
  flex: 0 0 auto;
  width: 34px;
  min-height: 44px;
  padding: 0;
}

.glazes button::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px var(--hairline);
}

.glazes button[aria-checked="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--sumi);
}

.status { min-height: 44px; }

#count { min-width: 4em; text-align: center; font-variant-numeric: tabular-nums; }

#progress {
  width: 120px;
  height: 1.5px;
  background: var(--hairline);
}

#progress i {
  display: block;
  height: 100%;
  background: var(--kin);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s;
}

/* Phones: centred rows. */
@media (max-width: 600px) {
  #bar { row-gap: 0; }
  .row { width: 100%; justify-content: space-between; }
  .glazes, .status { justify-content: center; gap: 10px; }
  button, .sheet-actions a { font-size: 14px; padding: 0 4px; letter-spacing: 0.02em; }
  .seal { padding: 0 8px; margin-left: 2px; }
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background: #e6e2d8;
}

.sheet[hidden] { display: none; }

#picture {
  max-width: 100%;
  max-height: calc(100% - 80px);
  min-height: 0;
  filter: drop-shadow(0 6px 18px rgba(60, 50, 30, 0.18));
  animation: settle 0.7s ease-out;
}

@keyframes settle {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.sheet-actions a {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.credits {
  display: grid;
  gap: 6px;
  text-align: center;
}

.credits dt {
  margin-top: 18px;
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.credits dt:first-child { margin-top: 0; }

.credits dd { font-size: 17px; }

.credits a {
  color: var(--sumi);
  text-decoration-color: var(--shu);
  text-underline-offset: 4px;
  -webkit-user-select: text;
  user-select: text;
}
