/* iPad 第6世代は横置きで 1024×768（CSSピクセル）。この大きさを基準に決めている */
:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --ink: #2b2b2b;
  --sub: #8a847b;
  --line: #e4ded4;
  --sun: #d23c3c;
  --sat: #2f6fd0;
  --accent: #e0893a;
  --today: #fff1df;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  /* 長押しで文字選択やコピーのメニューが出ると、カレンダーとして邪魔なので止める */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

#app {
  height: 100%;
  display: flex;
  gap: 14px;
  /* 全画面表示では上に時計・電池の帯がかぶるので、その分を空ける */
  padding: max(14px, env(safe-area-inset-top)) 14px 14px 14px;
}

/* ---------- カレンダー ---------- */
#cal {
  flex: 1 1 58%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 16px;
  padding: 10px 12px 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
#calHead {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 52px;
}
#ym {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: .02em;
  min-width: 230px;
  text-align: center;
}
/* 指で押す前提なので、ボタンは最低 44px 四方（Apple の推奨値）にする */
.nav {
  width: 48px;
  height: 48px;
  font-size: 34px;
  line-height: 1;
  border-radius: 12px;
  color: var(--sub);
}
.nav:active, .pill:active, .tool:active { background: var(--line); }
.pill {
  margin-left: auto;
  height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: 17px;
}
#dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--sub);
  padding: 6px 0 4px;
}
.sun { color: var(--sun) !important; }
.sat { color: var(--sat) !important; }
#grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  min-height: 0;
}
.cell {
  position: relative;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 4px 5px;
  overflow: hidden;
  min-width: 0;
}
/* 置き型なので少し離れて見る。19px では小さいと言われたので 28px にした（マスは約 77×106px） */
.cell .num {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.1;
}
.cell .hol {
  font-size: 12px;
  font-weight: 600;
  color: var(--sun);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell.other { background: #faf8f5; }
.cell.other .num, .cell.other .hol { opacity: .35; }
.cell.today { background: var(--today); }
.cell.today .num {
  display: inline-block;
  min-width: 38px;
  padding: 1px 6px;
  border-radius: 19px;
  background: var(--accent);
  color: #fff !important;
  text-align: center;
}
.cell.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.cell canvas.thumb {
  position: absolute;
  left: 3px; right: 3px; bottom: 3px;
  width: calc(100% - 6px);
  pointer-events: none;
}

/* ---------- 右側：時計とメモ ---------- */
#side {
  flex: 0 0 42%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
#clock {
  background: var(--panel);
  border-radius: 16px;
  padding: 10px 16px 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  text-align: center;
}
#time {
  font-size: 76px;
  font-weight: 300;
  line-height: 1;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
#date {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 600;
}
#holidayToday {
  font-size: 15px;
  color: var(--sun);
  min-height: 0;
}
#memoHead {
  display: flex;
  align-items: center;
  padding: 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--sub);
}
#memoWrap {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 16px;
  background:
    repeating-linear-gradient(to bottom, transparent 0 39px, #eee7dc 39px 40px),
    var(--panel);
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  overflow: hidden;
}
#memo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* ここで指を動かしたら、画面のスクロールではなく線を引く */
  touch-action: none;
}
#memoHint {
  position: absolute;
  left: 0; right: 0; top: 45%;
  text-align: center;
  color: #cfc7bb;
  font-size: 18px;
  pointer-events: none;
}
#tools {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
}
.color {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--c);
  border: 4px solid var(--bg);
  box-shadow: 0 0 0 1.5px var(--line);
}
.color.on { box-shadow: 0 0 0 3px var(--c); }
.tool {
  height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--panel);
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
#eraser { margin-left: auto; }
.tool.on { background: var(--accent); color: #fff; }
.tool.danger { color: var(--sun); }

/* 夜は画面を暗くする（触ると1分だけ明るく戻る） */
#night {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  z-index: 10;
}

/* ---------- 縦置き：上にカレンダー、下に時計とメモ ---------- */
@media (orientation: portrait) {
  #app { flex-direction: column; }
  #cal { flex: 0 0 52%; }
  #side { flex: 1; }
  #clock { display: flex; align-items: baseline; justify-content: center; gap: 18px; padding: 8px 16px; }
  #time { font-size: 56px; }
}
