:root {
  color-scheme: dark;
  --bg: #14161b;
  --panel: #1d2028;
  --edge: #2e323c;
  --ink: #e8e6e3;
  --dim: #9a9691;
  --accent: #d67756;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 16px 14px 40px;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1 { font-size: 19px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 6px; color: var(--accent); }

header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.header-actions { display: flex; gap: 8px; }

.note { color: var(--dim); font-size: 13px; margin: 4px 0 10px; }
.error { color: #e06c5a; min-height: 1.4em; }

button {
  font: inherit; font-weight: 600; color: #14161b; background: var(--accent);
  border: 0; border-radius: 10px; padding: 11px 14px; cursor: pointer;
}
button.ghost { background: var(--edge); color: var(--ink); font-weight: 500; }
button.link { background: none; color: var(--dim); font-weight: 500; padding: 6px; }

/* Secondary enough to be an icon, permanent enough to want a confirmation. */
button.icon {
  background: var(--edge); color: var(--dim);
  padding: 0; width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
}
button.icon svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
button.icon:active { color: var(--ink); }

input, select, textarea {
  /* 16px exactly. Below that, iOS Safari zooms the page the moment a field is
     focused, which pushes the save button off the screen — the field is legible
     either way, so the size is here for the zoom, not for the reading. */
  font-family: inherit; font-size: 16px;
  color: var(--ink); background: #101218;
  border: 1px solid var(--edge); border-radius: 8px; padding: 10px 11px; width: 100%;
}
input[readonly] { color: var(--dim); }

.screen { max-width: 720px; margin: 0 auto; }
#login-form { display: grid; gap: 10px; max-width: 340px; margin-top: 24px; }

/* The board: nine squares, always three across so the shape is the same on a
   phone and on a desktop. */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 8px;
  text-align: center;
  user-select: none;
}

/* Two invisible halves sit over the whole square. They are the tap targets, so
   a press anywhere on the left goes one way and the right goes the other. */
.half {
  position: absolute; top: 0; bottom: 0; width: 50%;
  background: none; border: 0; padding: 0; margin: 0;
  cursor: pointer; z-index: 2;
}
.half.left { left: 0; border-radius: 14px 0 0 14px; }
.half.right { right: 0; border-radius: 0 14px 14px 0; }
.half:active { background: rgba(255, 255, 255, 0.07); }

.cell-title {
  font-weight: 700; font-size: 14px; line-height: 1.3;
  max-height: 2.6em; overflow: hidden; margin-bottom: 4px;
}
.cell-title.empty { color: var(--dim); font-weight: 500; }

.cell-state {
  font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  color: #14161b;
}

.cell-remaining { font-size: 12px; color: var(--dim); margin-top: 4px; }

/* The countdown ring is drawn behind the text rather than beside it, so the
   square keeps its size whether or not a timer is running. */
.ring { position: absolute; inset: 6px; z-index: 0; pointer-events: none; }
.ring circle { fill: none; stroke-width: 3; }
.ring .track { stroke: rgba(255, 255, 255, 0.07); }
.ring .run { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }

.cell-hints {
  position: absolute; left: 0; right: 0; bottom: 5px; z-index: 1;
  display: flex; justify-content: space-between; padding: 0 9px;
  font-size: 10px; color: var(--dim); pointer-events: none;
}

.panel section {
  background: var(--panel); border: 1px solid var(--edge);
  border-radius: 12px; padding: 14px; margin-bottom: 12px;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }

.editor {
  display: grid; gap: 8px; padding: 10px 0;
  border-top: 1px solid var(--edge);
}
.editor:first-child { border-top: 0; }
.editor .fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.editor label { font-size: 12px; color: var(--dim); display: grid; gap: 4px; }
.editor .wide { grid-column: 1 / -1; }
.editor .actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.editor .actions .note { margin: 0; flex: 1 1 auto; text-align: left; }

dialog {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--edge); border-radius: 14px; padding: 18px; max-width: 320px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 14px 0 0; }

@media (max-width: 420px) {
  .cell-title { font-size: 13px; }
  .editor .fields { grid-template-columns: 1fr; }
}
