:root {
  --paper: #f6f3ea;
  --ink: #17201c;
  --muted: #66726d;
  --line: #d9d4c4;
  --panel: #fffdf7;
  --green: #0f7a5c;
  --green-dark: #075941;
  --blue: #2454a6;
  --amber: #d88a1d;
  --red: #b83a2f;
  --purple: #7b1fa2;
  --purple-dark: #4a148c;
  --shadow: 0 18px 45px rgba(23, 32, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic", sans-serif;
  background:
    linear-gradient(90deg, rgba(23, 32, 28, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(23, 32, 28, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(23, 32, 28, 0.13);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

.hero {
  display: grid;
  gap: 10px;
  margin-bottom: 24px;
  min-height: 100px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.lead {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.8;
  min-height: 3.6em;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: clamp(18px, 3vw, 28px);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.timer-panel,
.work-panel {
  border-top: 10px solid var(--muted);
}

.timer-panel.is-running,
.work-panel.is-running {
  border-top: 10px solid var(--red);
}

.timer-panel.is-paused,
.work-panel.is-paused {
  border-top: 10px solid var(--blue);
}

.panel-heading {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 6px 12px;
  min-height: 52px;
}

.panel-heading h2 {
  grid-column: 1;
  margin-bottom: 0;
  font-size: clamp(1.45rem, 3vw, 2.2rem);
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 12px);
}

.panel-heading h2 span {
  text-box: trim-both cap alphabetic;
}

.panel-icon {
  flex-shrink: 0;
  width: clamp(1.35rem, 3.2vw, 2rem);
  height: clamp(1.35rem, 3.2vw, 2rem);
  color: var(--muted);
  transition: color 240ms ease;
  transform-origin: center;
}

/* Running & Paused States */
.timer-panel.is-running .panel-icon {
  color: var(--red);
}

.work-panel.is-running .panel-icon {
  color: var(--red);
}

/* Hourglass sand stream falling animation (step-by-step) */
.timer-panel.is-running .sand-stream {
  animation: sand-fall 0.4s steps(3) infinite;
}

/* Hourglass sand draining and growing (ticking once per second) */
.timer-panel.is-running .top-sand {
  transform-origin: 12px 13px;
  animation: top-sand-drain 4s steps(4) infinite;
}

.timer-panel.is-running .bottom-sand {
  transform-origin: 12px 22px;
  animation: bottom-sand-grow 4s steps(4) infinite;
}

/* Stopwatch hand ticks once per second */
.work-panel.is-running .stopwatch-hand {
  transform-origin: 12px 13px;
  animation: stopwatch-hand-tick 12s steps(12) infinite;
}

.timer-panel.is-paused .panel-icon,
.work-panel.is-paused .panel-icon {
  color: var(--blue);
}

/* Discrete falling particles animation */
@keyframes sand-fall {
  to { stroke-dashoffset: -3; }
}

/* Hourglass top sand draining */
@keyframes top-sand-drain {
  from { transform: scaleY(1); }
  to { transform: scaleY(0); }
}

/* Hourglass bottom sand accumulating */
@keyframes bottom-sand-grow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

/* Mechanical second-hand tick for stopwatch (1 tick per second) */
@keyframes stopwatch-hand-tick {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.status-pill {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: #f7f7f2;
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
  min-width: 72px;
  text-align: center;
}

.status-pill[data-state="active"],
.status-pill[data-state="working"] {
  color: #ffffff;
  border-color: #8f251d;
  background: var(--red);
}

.status-pill[data-state="resting"],
.status-pill[data-state="paused"] {
  color: #ffffff;
  border-color: #1a3c78;
  background: var(--blue);
}

.status-pill[data-state="done"] {
  color: #ffffff;
  border-color: var(--red);
  background: var(--red);
}



.time-display {
  margin: 30px 0 24px;
  padding: 18px 16px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  overflow-wrap: anywhere;
  text-align: center;
  font-family: "Courier New", monospace;
  font-size: clamp(2.4rem, 7vw, 5rem);
  font-weight: 800;
  line-height: 1;
  background: #e5e8e6;
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90px;
}

.time-inputs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 48px;
  gap: 10px;
  align-items: end;
  min-height: 82px;
}

.time-inputs label {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
}

.time-inputs input {
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #ffffff;
  font-size: 1.35rem;
  font-weight: 700;
}

.time-clear-button {
  width: 48px;
  min-height: 58px;
  padding: 0;
  display: grid;
  place-items: center;
}

.reset-arrow-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--ink);
}

.preset-row,
.control-grid,
.state-actions {
  display: grid;
  gap: 10px;
}

.preset-row {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin: 10px 0 14px;
  min-height: 40px;
}

.preset-row button {
  min-width: 0;
  min-height: 32px;
  padding: 4px 2px;
  border-radius: 5px;
  font-size: 0.72rem;
  white-space: nowrap;
  font-weight: 700;
}

.control-grid {
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  min-height: 52px;
}

.primary,
.work-start {
  color: #ffffff;
  border-color: #8f251d;
  background: var(--red);
}

.work-rest,
[data-timer-stop] {
  color: #ffffff;
  border-color: #1a3c78;
  background: var(--blue);
}

.work-reset-action {
  color: var(--ink);
  border-color: var(--ink);
  background: #ffffff;
}

[data-timer-restart] {
  color: var(--ink);
  border-color: var(--ink);
  background: #f1c40f;
}

[data-timer-restart]:hover:not(:disabled) {
  background: #d4ac0d;
}

.state-actions {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 12px;
  min-height: 52px;
}

.is-active {
  outline: 3px solid rgba(36, 84, 166, 0.35);
  outline-offset: 3px;
}

.volume-control-container {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.lang-selector {
  display: inline-flex;
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
}

.lang-btn {
  border: none;
  background: none;
  min-height: 38px;
  padding: 0 16px;
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  border-radius: 0;
}

.lang-btn:not(:last-child) {
  border-right: 2px solid var(--ink);
}

.lang-btn:hover {
  background: var(--line);
  color: var(--ink);
}

.lang-btn.active {
  background: var(--ink);
  color: var(--paper);
}

.volume-control {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 10px 20px;
}

.volume-mute-toggle {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  min-height: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: color 120ms ease, transform 120ms ease;
}

.volume-mute-toggle:hover {
  color: var(--ink);
  transform: scale(1.1);
}

.volume-mute-toggle:focus-visible {
  outline: 2px solid var(--blue);
  border-radius: 4px;
}

.volume-mute-toggle .volume-icon .mute-slash {
  display: none;
}

.volume-mute-toggle.is-muted .volume-icon .volume-waves {
  display: none;
}

.volume-mute-toggle.is-muted .volume-icon .mute-slash {
  display: block;
}

.volume-icon {
  color: inherit;
  flex-shrink: 0;
}

.volume-control label {
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
}

.volume-control input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  outline: none;
}

.volume-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.volume-control input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  background: var(--line);
}

.volume-percentage {
  font-family: "Courier New", monospace;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--ink);
  min-width: 4ch;
  text-align: right;
}

.ad-slot {
  width: min(1180px, calc(100% - 32px));
  min-height: 90px;
  margin: 16px auto 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 18px auto 28px;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 40px;
}

.site-footer a,
.back-link {
  color: var(--blue);
  font-weight: 800;
}

.policy-page {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 44px 0;
  line-height: 1.8;
}

.policy-page h1 {
  margin: 18px 0 24px;
  font-size: clamp(2rem, 6vw, 3.8rem);
}

.policy-page section {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 22px;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 560px);
    padding-top: 22px;
  }

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

  .panel {
    padding: 16px;
  }

  .time-display {
    margin: 22px 0 18px;
  }

  .control-grid,
  .state-actions {
    grid-template-columns: 1fr;
  }

  .ad-slot {
    width: min(100% - 20px, 560px);
    min-height: 76px;
  }
}

@media (max-width: 420px) {
  .panel-heading {
    grid-template-columns: 1fr;
  }

  .status-pill {
    grid-row: auto;
    grid-column: 1;
    justify-self: start;
  }

  .preset-row {
    display: flex;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .preset-row button {
    flex: 0 0 58px;
  }

  .time-inputs {
    grid-template-columns: repeat(3, minmax(0, 1fr)) 44px;
    gap: 6px;
  }

  .time-clear-button {
    width: 44px;
  }
}

.work-total {
  cursor: pointer;
}

.work-total span {
  transition: background-color 160ms ease, color 160ms ease;
  border-radius: 4px;
  padding: 0 4px;
}

.work-total span:hover {
  background-color: rgba(23, 32, 28, 0.08);
  color: var(--ink);
}

.secondary-time-displays {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(8px, 2vw, 16px);
  margin-top: 8px;
  margin-bottom: 24px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 12px clamp(8px, 2vw, 16px);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.45);
  min-height: 60px;
}

.secondary-time-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.secondary-time-label {
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.secondary-time-val {
  font-family: "Courier New", monospace;
  font-weight: 800;
  font-size: clamp(1.1rem, 2.5vw, 1.45rem);
  color: var(--ink);
}

.work-edit-mode {
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.work-edit-mode input {
  box-sizing: content-box !important;
  width: 2ch;
  height: 1em !important;
  border: none !important;
  background: transparent !important;
  padding: 0 4px !important;
  margin: 0 !important;
  color: inherit !important;
  font-family: inherit !important;
  font-size: inherit !important;
  font-weight: inherit !important;
  line-height: 1 !important;
  text-align: center;
  outline: none !important;
  box-shadow: none !important;
  -moz-appearance: textfield;
}

.work-edit-mode input::-webkit-outer-spin-button,
.work-edit-mode input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.hidden {
  display: none !important;
}

/* Work end button style */
.work-end {
  color: #ffffff;
  border-color: var(--green-dark);
  background: var(--green);
}

.work-end:hover:not(:disabled) {
  background: var(--green-dark);
}

/* View Log button and container */
.log-action-container {
  margin-top: 20px;
  min-height: 48px;
}

.view-log-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #ffffff;
  border: 1px solid var(--ink);
  font-weight: 700;
  min-height: 40px;
}

.button-icon {
  flex-shrink: 0;
}

/* Calendar Log Modal styling */
.log-modal {
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 0;
  width: min(540px, 92vw);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.log-modal::backdrop {
  background: rgba(23, 32, 28, 0.45);
  backdrop-filter: blur(4px);
}

.log-modal .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 2px solid var(--ink);
  background: var(--paper);
}

.log-modal .modal-header h2 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ink);
}

.log-modal .close-button {
  background: transparent;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  min-height: auto;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: color 160ms ease;
}

.log-modal .close-button:hover {
  color: var(--red);
  box-shadow: none;
  transform: none;
}

.log-modal .modal-body {
  padding: 20px;
}

/* Log list styling */
.log-list-container {
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Custom scrollbar for premium feel */
.log-list-container::-webkit-scrollbar {
  width: 6px;
}

.log-list-container::-webkit-scrollbar-track {
  background: transparent;
}

.log-list-container::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}

.log-list-container::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  margin-bottom: 8px;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.log-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(23, 32, 28, 0.05);
  border-color: var(--ink);
}

.log-item-date {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--ink);
}

.log-item-duration {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--green);
}

.log-item-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.edit-log-btn {
  background: transparent !important;
  border: none !important;
  font-size: 0.78rem !important;
  font-weight: 800 !important;
  line-height: 1 !important;
  padding: 0 4px !important;
  min-height: auto !important;
  cursor: pointer;
  color: var(--blue) !important;
  transition: color 160ms ease, transform 160ms ease;
  box-shadow: none !important;
}

.edit-log-btn:hover {
  color: var(--ink) !important;
  transform: scale(1.05) !important;
}

.delete-log-btn {
  background: transparent !important;
  border: none !important;
  font-size: 1.4rem !important;
  line-height: 1 !important;
  padding: 0 !important;
  width: 24px;
  height: 24px;
  min-height: auto !important;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--muted) !important;
  transition: color 160ms ease, transform 160ms ease;
  box-shadow: none !important;
}

.delete-log-btn:hover {
  color: var(--red) !important;
  transform: scale(1.15) !important;
  box-shadow: none !important;
}

.log-item-edit-form {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--muted);
}

.log-item-edit-form input {
  width: 3.5ch;
  border: 1px solid var(--line) !important;
  border-radius: 4px;
  padding: 2px 4px !important;
  text-align: center;
  font-size: 0.85rem !important;
  font-weight: 700 !important;
  background: #ffffff !important;
  color: var(--ink) !important;
  -moz-appearance: textfield;
}

.log-item-edit-form input::-webkit-outer-spin-button,
.log-item-edit-form input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.save-log-btn {
  background: var(--green) !important;
  color: #ffffff !important;
  border: 1px solid var(--green-dark) !important;
  border-radius: 4px;
  padding: 4px 8px !important;
  font-size: 0.75rem !important;
  font-weight: 800 !important;
  min-height: auto !important;
  cursor: pointer;
  box-shadow: none !important;
}

.save-log-btn:hover {
  background: var(--green-dark) !important;
  transform: translateY(-1px);
}

.cancel-log-btn {
  background: #ffffff !important;
  color: var(--ink) !important;
  border: 1px solid var(--ink) !important;
  border-radius: 4px;
  padding: 4px 8px !important;
  font-size: 0.75rem !important;
  font-weight: 800 !important;
  min-height: auto !important;
  cursor: pointer;
  box-shadow: none !important;
}

.cancel-log-btn:hover {
  background: #f7f7f2 !important;
  transform: translateY(-1px);
}

.log-empty-msg {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.log-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.log-item-endtime {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 4px;
}

.log-item-durations {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 800;
}

.log-item-duration-work {
  color: var(--green);
}

.log-item-duration-rest {
  color: var(--blue);
}

.toast-notification {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--green);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 12px 28px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 122, 92, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease, transform 300ms ease;
  z-index: 9999;
}

.toast-notification.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
