:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #15202b;
  --muted: #657487;
  --line: #d8e0e8;
  --accent: #1570ef;
  --accent-strong: #0b4fb3;
  --green: #067647;
  --red: #b42318;
  --shadow: 0 18px 60px rgba(28, 39, 49, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  padding-bottom: 88px;
  background:
    radial-gradient(circle at 15% 10%, rgba(21, 112, 239, 0.12), transparent 30%),
    linear-gradient(135deg, #f8fafc 0%, var(--bg) 52%, #eef5f2 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.add-watch {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.add-watch:disabled {
  border-color: var(--line);
  background: #eef2f6;
  color: var(--muted);
  cursor: not-allowed;
}

.study-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.watch-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.drop-indicator {
  position: fixed;
  z-index: 30;
  display: none;
  width: 6px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(21, 112, 239, 0.16);
  pointer-events: none;
}

.drop-indicator::after {
  content: "ここに入る";
  position: absolute;
  top: -34px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(21, 112, 239, 0.24);
}

.watch-grid.drag-active .drop-indicator {
  display: block;
}

.watch-grid[data-count="1"] {
  grid-template-columns: minmax(0, 1fr);
}

.watch-grid[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.today-panel {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid rgba(216, 224, 232, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.today-panel h2 {
  margin: 0 0 4px;
  font-size: 1rem;
  letter-spacing: 0;
}

.today-date {
  display: block;
  margin-top: -4px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.today-total {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.today-total span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.today-total strong {
  font-family: "SF Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 1.55rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.today-total.study strong {
  color: var(--accent);
}

.today-total.rest strong {
  color: var(--red);
}

.watch {
  min-width: 0;
  min-height: 460px;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(216, 224, 232, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.order-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.drag-handle,
.order-button {
  width: fit-content;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid #d8e0e8;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: grab;
}

.order-button {
  width: 34px;
  padding: 0;
  cursor: pointer;
}

.drag-handle:disabled,
.order-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.watch.dragging {
  opacity: 0.58;
  transform: scale(0.97);
  box-shadow: 0 10px 28px rgba(21, 32, 43, 0.12);
}

.watch.drop-left {
  transform: translateX(12px);
}

.watch.drop-right {
  transform: translateX(-12px);
}

.watch.reorder-flash {
  animation: reorderFlash 520ms ease;
}

.watch[hidden] {
  display: none;
}

@keyframes reorderFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(21, 112, 239, 0);
  }

  35% {
    box-shadow: 0 0 0 5px rgba(21, 112, 239, 0.22), var(--shadow);
  }

  100% {
    box-shadow: var(--shadow);
  }
}

.watch-header {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 18px 18px 8px;
}

.name-editor {
  min-width: 0;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  border: 1px solid #c9d6e4;
  border-radius: 8px;
  background: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.75);
  cursor: text;
}

.name-editor:hover {
  border-color: var(--accent);
  background: #fff;
}

.name-editor:focus-within {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(21, 112, 239, 0.16);
}

.watch-name {
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 2.15rem;
  font-weight: 800;
  line-height: 1.05;
  outline: none;
}

.watch-name:focus {
  border-bottom-color: transparent;
}

.edit-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: #e7f0ff;
  color: var(--accent);
  font-size: 1.15rem;
  font-weight: 900;
}

.watch-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.color-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.name-color {
  width: 38px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.name-color::-webkit-color-swatch-wrapper {
  padding: 0;
}

.name-color::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

.status {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
}

.delete-watch {
  min-height: 36px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fff7f6;
  color: var(--red);
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.delete-watch:hover:not(:disabled) {
  background: #fff0ee;
  border-color: #f97066;
}

.delete-watch:disabled {
  background: #f8fafc;
  color: #aab4c0;
  cursor: not-allowed;
}

.watch.running .status {
  background: #dcfae6;
  color: var(--green);
}

.display {
  display: block;
  max-width: 100%;
  padding: 36px 16px 18px;
  font-family: "SF Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 3.05rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

.break-meter {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 0 18px 10px;
  padding: 12px 14px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fff4f3;
  color: var(--red);
}

.break-total {
  grid-template-columns: 1fr auto auto;
  margin-bottom: 22px;
  border-color: #fedf89;
  background: #fffbeb;
  color: #a15c07;
}

.break-total button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #fdb022;
  border-radius: 8px;
  background: #fff;
  color: #a15c07;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.break-total button:hover {
  background: #fff7da;
}

.watch.running .break-meter {
  border-color: var(--line);
  background: #f8fafc;
  color: var(--muted);
}

.break-meter span {
  font-size: 0.82rem;
  font-weight: 800;
}

.break-meter strong {
  font-family: "SF Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.controls {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 8px;
  padding: 0 18px 18px;
}

.controls button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.controls button:hover {
  border-color: #9fb3ca;
}

.controls .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.watch.running .controls .primary {
  border-color: var(--red);
  background: var(--red);
}

.records {
  flex: 1;
  border-top: 1px solid var(--line);
  background: #fbfcfe;
  min-height: 0;
}

.record-section {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.record-section h2 {
  margin: 0;
  padding: 12px 14px 8px;
  color: var(--ink);
  font-size: 0.82rem;
  letter-spacing: 0;
}

.record-list {
  flex: 1;
  margin: 0;
  padding: 0 14px 14px 34px;
  color: var(--muted);
  overflow: auto;
}

.record-list:empty::before {
  content: "ラップなし";
  display: block;
  padding-top: 9px;
  margin-left: -24px;
  color: #8c9bae;
}

.record-list li {
  padding: 9px 0;
  border-bottom: 1px solid #e8edf2;
  font-family: "SF Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.confirm-dialog {
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(21, 32, 43, 0.25);
}

.confirm-dialog::backdrop {
  background: rgba(21, 32, 43, 0.42);
}

.confirm-dialog form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.confirm-dialog h2 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.dialog-actions button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.dialog-actions .danger {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.ad-banner {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) minmax(170px, 340px) 40px;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  padding: 12px 16px 12px 44px;
  border-top: 1px solid #d7dde5;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 -12px 34px rgba(21, 32, 43, 0.08);
}

.ad-logo {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #34a853, #fbbc05 52%, #4285f4);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 900;
}

.ad-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.ad-copy strong {
  color: #3f4854;
  font-size: 1rem;
}

.ad-copy span {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ad-button {
  display: grid;
  min-height: 44px;
  place-items: center;
  border-radius: 999px;
  background: #6b8fd6;
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 8px 18px rgba(73, 101, 164, 0.28);
}

.ad-menu {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #7a8694;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 900px) {
  .study-layout {
    grid-template-columns: 1fr;
  }

  .today-panel {
    position: static;
    grid-template-columns: 1fr 1fr;
  }

  .today-panel h2 {
    grid-column: 1 / -1;
  }

  .today-date {
    grid-column: 1 / -1;
  }

  .watch-grid {
    grid-template-columns: 1fr;
  }

  .watch {
    min-height: 390px;
  }

  .display {
    font-size: 3.5rem;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 24px 0;
  }

  .display {
    padding: 34px 14px 20px;
    font-size: 2.75rem;
  }

  .break-meter {
    grid-template-columns: 1fr;
  }

  .break-total {
    grid-template-columns: 1fr;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .watch-header {
    align-items: start;
    flex-wrap: wrap;
  }

  .name-editor {
    flex-basis: 100%;
  }

  .record-section {
    min-height: 160px;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }

  body {
    padding-bottom: 132px;
  }

  .ad-banner {
    grid-template-columns: 42px minmax(0, 1fr) 32px;
    gap: 10px;
    padding: 12px;
  }

  .ad-button {
    grid-column: 1 / -1;
    min-height: 40px;
  }
}
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .today-panel {
    grid-template-columns: 1fr;
  }

  .add-watch {
    width: 100%;
  }
