* {
  box-sizing: border-box;
}

:root {
  --bg: #ffffff;
  --fg: #000000;
  --panel: rgba(255, 255, 255, 0.90);
  --panel-border: rgba(0, 0, 0, 0.20);
  --accent: #1565c0;
  --footer-bg: rgba(246, 249, 255, 0.94);
}

body.dark {
  --bg: #000000;
  --fg: #ffffff;
  --panel: rgba(0, 0, 0, 0.84);
  --panel-border: rgba(255, 255, 255, 0.36);
  --footer-bg: rgba(0, 0, 0, 0.94);
}

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

body {
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans JP", "Yu Gothic", sans-serif;
  transition: background-color 0.18s ease, color 0.18s ease;
  user-select: none;
}

button {
  font: inherit;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.toolbar {
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 10px 8px;
  background: linear-gradient(to bottom, var(--bg), rgba(255,255,255,0));
}

body.dark .toolbar {
  background: linear-gradient(to bottom, var(--bg), rgba(0,0,0,0));
}

.tool-btn {
  min-width: 112px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--fg);
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.tool-btn.active {
  border-color: #1e88ff;
  color: #1e88ff;
  font-weight: 700;
}

.clock-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 2px 12px 8px;
}

.clock-shell {
  position: relative;
  width: min(90vmin, 920px);
  height: min(90vmin, 920px);
  display: grid;
  place-items: center;
}

#clockCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.digital-clock {
  width: min(90vmin, 980px);
  min-height: min(35vmin, 330px);
  display: grid;
  place-items: center;
  border: clamp(2px, 0.35vmin, 5px) solid var(--panel-border);
  border-radius: 16px;
  font-variant-numeric: tabular-nums;
  font-size: clamp(3.4rem, 17vmin, 12rem);
  font-weight: 800;
  letter-spacing: 0.045em;
  line-height: 1;
}

.hidden {
  display: none !important;
}

.site-footer {
  text-align: center;
  color: #1565c0;
  font-size: 0.78rem;
  line-height: 1.2;
  padding: 5px 8px 7px;
  border-top: 1px solid rgba(21,101,192,0.16);
  background: var(--footer-bg);
}

.site-footer a {
  color: #1565c0;
  text-decoration: none;
  font-weight: 700;
}

.site-footer a:hover {
  color: #0d47a1;
}

.ad-panel {
  width: min(920px, calc(100% - 16px));
  margin: 6px auto 8px;
  border: 1px solid #d7e6f8;
  border-radius: 10px;
  background: #ffffff;
  color: #333333;
  overflow: hidden;
}

.ad-panel[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  height: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  background: #f4f8ff;
  border-bottom: 1px solid #d7e6f8;
}

.ad-label,
.ad-wait {
  font-size: 0.72rem;
  color: #4f6f91;
  line-height: 1.2;
}

.ad-close-btn {
  display: none;
  margin: 0 !important;
  padding: 3px 8px !important;
  min-height: 0;
  height: auto;
  line-height: 1.2;
  border: none;
  border-radius: 999px;
  background: #1565c0;
  color: #ffffff;
  font-size: 0.72rem !important;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.ad-close-btn:hover {
  background: #0d47a1;
}

.ad-body {
  padding: 8px;
  background: #ffffff;
  min-height: 70px;
  display: grid;
  place-items: center;
}

body.fullscreen-active .toolbar {
  opacity: 0.18;
  transition: opacity 0.2s ease;
}

body.fullscreen-active .toolbar:hover,
body.fullscreen-active .toolbar:focus-within {
  opacity: 1;
}

@media (orientation: landscape) and (min-width: 900px) {
  .clock-shell {
    width: min(82vmin, 920px);
    height: min(82vmin, 920px);
  }
}

@media (max-width: 520px) {
  .tool-btn {
    min-width: 94px;
    padding: 8px 10px;
    font-size: 0.86rem;
  }

  .toolbar {
    gap: 6px;
  }
}
